I am playing video in my application
_player = [[MPMoviePlayerController alloc] init];
_player.view.frame = CGRectMake(0, 60, frame.size.width,frame.size.height - 130);
_player.movieSourceType = MPMovieSourceTypeStreaming;
_player.fullscreen = NO;
[_player setScalingMode:MPMovieScalingModeAspectFill];
_player.controlStyle = MPMovieControlStyleNone;
[_player setContentURL:[NSURL URLWithString:mediaUrl]];
[_player play];
And i have to do some configuration -
1- If device is silent then play video with full volume. 2- If device is playing any music in another application then have to pause the background songs and play again when video play completed.
So i searched a lot then found following solutions -
For 1-
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
its working perfectly when device is silent.then its playing in full volume.
For 2- Both background song and Video audio playing both, I am doing following -
- (void)viewWillAppear:(BOOL)animated {
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
}
-(void)viewWillDisappear:(BOOL)animated {
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
[[AVAudioSession sharedInstance] setActive:NO error:nil];
}
But its not working, its stoping background music but not playing again.