I am using MPMoviePlayerController to play a video into my application. Below is my code for playing video.
**NSURL *url=[[NSURL alloc] initFileURLWithPath:urlPath];
if(moviePlayer)
{
[moviePlayer.view removeFromSuperview];
moviePlayer = nil;
}
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.repeatMode = MPMovieRepeatModeOne;
moviePlayer.currentPlaybackTime = 0.0;
moviePlayer.view.frame = _viewMoviePlayer.frame;
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
[_viewMoviePlayer addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];
[self.view sendSubviewToBack:_viewMoviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];**
When viewWillDisappear called, then I just stop moviePlayer and remove it from view. But my default music player is running but didn't sound for it. When I closed my application, it will.
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[moviePlayer stop];
[moviePlayer.view removeFromSuperview];
moviePlayer = nil;
[_viewMoviePlayer removeFromSuperview];
_viewMoviePlayer = nil;
}
Can anyone tell which is going wrong in my code? So I am release the moviePlayer then it will play default music as it should. when I check current sound for Music then its ohk and also its show song is running in Music app. But didn't get sound.
I faced with same issue. I just created one separate controller. Below is my code for same:
Hope it will helpful to you... :)