Reputation: 51
I am trying to play streaming file from particular URL using MPMoviePlayerController. It is working fine when I load the player but I need to keep it running when application enter into the background mode (Multitasking). This is what I am doing:
-(void) playAudio :(NSString *)playAudioURL
{
//NSURLRequest *audioFile = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString:self.playAudioURL] cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 10];
MPMoviePlayerController *mediaPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:playAudioURL]];
mediaPlayer.scalingMode = MPMovieScalingModeAspectFill;
mediaPlayer.scalingMode = MPMovieScalingModeAspectFill;
mediaPlayer.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Home-bg.png"]];
//[self.view addSubview:mediaPlayer.view];
mediaPlayer.fullscreen = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mediaPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoPreloadCallback:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:mediaPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
[mediaPlayer play];
}
Now when I press iPhone home button while running the audio, it pauses the streaming until I load back the Application. I need to keep it running when app enter into background.
Upvotes: 0
Views: 5644
Reputation: 171
In your plist file, did you set the UIBackgroundModes
key to audio ? Without this, your application will not play any sound in background
Note that in iOS5, UIBackgroundModes
is now referenced as Required background modes
when you edit your plist file.
Upvotes: 1