播放视频我已经在我的应用程序的info.plist中设置应用程序播放音频为所需的背景模式,以保持mpmovieplayerviewcontroller后不去背景后解雇。它做得很好。然而,苹果公司最近拒绝了我的应用程序的更新,因为我设置了该属性。MPMoviePlayerViewController播放视频后为youtube
然后我一直在找同样的工作但失败的解决方案。为了对付它,我救currentplaybacktime当视图控制器接收使用UIApplicationDidEnterBackgroundNotification
-(void)willEnterBackground {
NSLog(@"willEnterBackground");
if (self.mp) {
playbackTime = self.mp.moviePlayer.currentPlaybackTime;
[self.mp dismissModalViewControllerAnimated:YES];
}
}
它接收UIApplicationWillEnterForegroundNotification后设置currentPlayBackTime:
- (void)willEnterForeground {
NSLog(@"willEnterForeground");
if (!self.mp)
return;
if(self.mp.moviePlayer.playbackState == MPMoviePlaybackStateInterrupted || self.mp.moviePlayer.playbackState == MPMoviePlaybackStateStopped || self.mp.moviePlayer.playbackState == MPMoviePlaybackStatePaused)
{
[self continuePlayback];
}
}
- (void)continuePlayback {
NSLog(@"%f", self.mp.moviePlayer.duration);
NSLog(@"%f", playbackTime);
[self.mp.moviePlayer stop];
self.mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[self.videos objectForKey:@"medium"]]] ;
[self.mp.moviePlayer setInitialPlaybackTime:playbackTime];
[self.mp.moviePlayer play];
[self presentModalViewController:self.mp animated:YES];
}
它的工作原理,但也有一些权衡: 正如我重新初始化它,它丢失了流式视频部分。用户需要等待再次播放。
这里来我的问题:
- 是否有不断流的Youtube的视频时,应用程序在后台 的方法吗?
- 或如何保持流媒体部分?
self.mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[self.videos objectForKey:@"medium"]]] ;
在continuePlayBack方法或我setCurrentPlayBackTime代替setInitPlayBackTime:
它将从视频的开头,如果我跳过线玩。
http://stackoverflow.com/questions/13023241/continue-playing-movie-in-mpmovieplayerviewcontroller-in-background/21752593#21752593 – 2014-02-13 11:15:45