按下UIbutton后,视频出现并开始播放.
不幸的是,3-4秒后,视频变黑,音频仍在播放.
有任何想法吗?
谢谢你所有的时间.
(使用Xcode 4.2.1)
-(voID) playMovIEbuttonpressed:(UIbutton*) button{ Nsstring* vIDeo = @"testmovIE.m4v"; Nsstring *filepath = [[NSBundle mainBundle] pathForResource: ofType:]; NSURL *fileURL = [NSURL fileURLWithPath:filepath]; MPMovIEPlayerController* player = [[MPMovIEPlayerController alloc] initWithContentURL:fileURL]; [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(movIEPlaybackComplete:) name:MPMovIEPlayerPlaybackDIDFinishNotification object:player]; player.movIESourceType = MPMovIESourceTypefile; [player.vIEw setFrame:CGRectMake(20,400,300,200)]; [self.vIEw addSubvIEw:player.vIEw]; [player preparetoPlay]; [player play]; }- (voID) movIEPlaybackComplete:(NSNotification*) notification { NSLog(@"vIDeovIEwcontroller complete: %@",notification); MPMovIEPlayerController *mymovIEPlayerController = [notification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMovIEPlayerPlaybackDIDFinishNotification object:mymovIEPlayerController]; }解决方法 我和一位Apple工程师谈过了.解决方案是播放器必须是视图控制器的实例变量或属性.所以当视图被拆除时它仍然可以访问.
-(voID) playMovIEbuttonpressed:(UIbutton*) button{ Nsstring* vIDeo = @"testmovIE.m4v"; Nsstring *filepath = [[NSBundle mainBundle] pathForResource: ofType:]; NSURL *fileURL = [NSURL fileURLWithPath:filepath]; self.movIEPlayerController = [[MPMovIEPlayerController alloc] initWithContentURL:fileURL]; // .....}总结
以上是内存溢出为你收集整理的ios – 视频播放几秒钟后消失全部内容,希望文章能够帮你解决ios – 视频播放几秒钟后消失所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)