Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to support to play audio file in the background
    text
    copied!<p>There is a function in my project to support playing a new audio file even in the background status.I use the MPMoviePlayerController class to play audio files. But I found it was started in the active status,then it would continue playing the same audio(if the audio file wasn't finished) in the background status;But it won't start a new audio in the background status.</p> <p>How can I to support playing a new audio in the backgound status? I found the music player of the iphone can support playing a new audio in the background status,when set runloop or random PlayMode.</p> <p>The following is my code to prove the appearance in fact:</p> <pre><code>(void)applicationDidEnterBackground:(UIApplication *)application { if (pCotnroller1) { [pCotnroller1 release]; } pCotnroller1 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://r.yhiker.com:9001/0086/32/05/060009/Data/6/00863205060009006_24Kbps.mp3"]]; pCotnroller1.shouldAutoplay = YES; [pCotnroller1 play]; //it wasn't played here } (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. if (pCotnroller1) { switch (pCotnroller1.playbackState) { case MPMoviePlaybackStateStopped: NSLog(@"播放地址"); break; case MPMoviePlaybackStatePaused: NSLog(@"播放暂停"); break; case MPMoviePlaybackStateInterrupted: NSLog(@"播放中断"); break; case MPMoviePlaybackStateSeekingBackward: break; case MPMoviePlaybackStateSeekingForward: break; default: break; } if (pCotnroller1.playbackState == MPMoviePlaybackStatePlaying) { //it will come here,and play autoed here // [pCotnroller1 play]; } else { } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload