- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
*我正在创建一个 iPhone 应用程序,我们可以在其中观看视频...我一直在制作自己的控件,所以我想实现下一个后退按钮,我可以显示主题,所以对于 UI 来说一切正常,问题是用另一个内容重新启动 MoviePlayer ...有什么想法吗???
我可以在播放完成后使用相同的配置,我的意思是...如果视频结束播放以开始播放另一个...我试图设置 contentUrl 但它抛出了一个异常:
2012-04-17 11:37:41.198 NexTest2[8218:11f03] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 11.5]'
viewController.m
- (void)viewDidLoad{
[super viewDidLoad];
fileURL = [NSURL URLWithString:urlString];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[moviePlayerController setShouldAutoplay:YES];
[self addObservers];
/* Inset the movie frame in the parent view frame. */
CGRect viewInsetRect = CGRectInset ([self.view bounds],0.0, 0.0 );
[[moviePlayerController view] setFrame: viewInsetRect ];
[self.view addSubview:moviePlayerController.view];
[self resizeControlViews];
}
然后在 resizeControlViews 中我有这个,因为我正在使用这两个像控件一样的 View :
-(void)resizeControlViews{
CGRect barFrame = self.controlBarView.frame;
barFrame.origin.x = round((moviePlayerController.view.frame.size.width - barFrame.size.width) / 2.0);
barFrame.origin.y = round((moviePlayerController.view.frame.size.height - barFrame.size.height)/10.0);
self.controlBarView.frame = barFrame;
[moviePlayerController.view addSubview:controlBarView];
CGRect playFrame = self.controlPlaybackView.frame;
playFrame.origin.x = round((moviePlayerController.view.frame.size.width - playFrame.size.width) / 2.0);
playFrame.origin.y = round((moviePlayerController.view.frame.size.height - playFrame.size.height)/1.1);
self.controlPlaybackView.frame = playFrame;
[moviePlayerController.view addSubview:controlPlaybackView];
}
这里一切正常,在其中一个 View 中有一个控制搜索的 slider ,在另一个 View 中是播放、下一个和后退按钮。我认为问题可能出在这些 View 的 UI 组件上......
我添加了这些观察者来控制播放:
//Add the observers to the player
-(void)addObservers{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackStarted:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setDurationLabel:) name:MPMovieDurationAvailableNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyWindowChanged:) name:UIWindowDidBecomeKeyNotification object:nil];
}
为了在播放器播放时进行处理,我将 MPMoviePlayerPlaybackStateDidChangeNotification 与此选择器一起使用:
//called when the playback state changes of state
- (void)playbackStarted:(NSNotification*)notification {
MPMoviePlayerController *player = notification.object;
if (player.playbackState == MPMoviePlaybackStatePlaying) {
[self timerRunning];
}
}
如果玩家正在“玩”,我会用这种方法监控它:
-(void)timerRunning{
self.currentTime.text = [self floatToStringTime:(moviePlayerController.currentPlaybackTime)];
self.timeBar.value = moviePlayerController.currentPlaybackTime / moviePlayerController.duration;
if (moviePlayerController.playbackState == MPMoviePlaybackStatePlaying) {
[self performSelector:@selector(timerRunning) withObject:nil afterDelay:0.5];
}
}
所以也许这就是问题所在......但是对于单个视频来说它可以完美地工作......
我有四个错误是...当我在线监视以设置 slider 的值时,但我真的不知道为什么,我认为这是另一个视频或停止时的原因视频它仍然在执行所以播放器没有持续时间或当前播放是什么导致了这个异常......我怎么能解决它......这是错误......也许将这段代码移动到另一部分......
self.timeBar.value = moviePlayerController.currentPlaybackTime / moviePlayerController.duration;
最佳答案
检查您的 UI 相关代码。在从中获取和使用与内容相关的属性之前,您很可能没有正确检查播放器状态。
关于iphone - 如何在同一个 MPMoviePlayerController 中播放另一个视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10189031/
我是一名优秀的程序员,十分优秀!