OGeek|极客世界-中国程序员成长平台

标题: iphone - ios MPMoviePlayerController 无法在模拟器上播放本地文件 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:47
标题: iphone - ios MPMoviePlayerController 无法在模拟器上播放本地文件

我是新来的。我已经浏览了 2 天的解决方案,但不满意。

这是我的代码:

NSString *docPath = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *docaPathFull = [docPath stringByAppendingPathComponent"/IMG_0003.m4v"];
self.videoURL = [NSURL fileURLWithPath:docaPathFull];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
UIImage  *thumbnail = [player thumbnailImageAtTime:4.0 timeOption:MPMovieTimeOptionExact];
player = nil;       
self.imageView.image = thumbnail;

问题是,我无法使 MPMoviePlayerController 的视频文件可见。我无法获得缩略图,也无法播放,只有黑色播放器和无限加载。

我试过了:

NSString*thePath=[[NSBundle mainBundle] pathForResource"IMG_0003" ofType"m4v"];
self.videoURLtheurl=[NSURL fileURLWithPath:thePath];

还有这个

self.videoURL = [[NSBundle mainBundle] URLForResource"IMG_0005" withExtension"mov"];

还有这个

NSString *filePath = @"/Users/[user]/Documents/video/IMG_0004.mov";
self.videoURL = [NSURL fileURLWithPath:filePath];

如果你有任何想法如何拯救我的生命,请做!!!

非常感谢您的宝贵时间。



Best Answer-推荐答案


实际上,这是我项目中的工作示例。确保将 m4v 文件添加到项目中。通知对我来说是需要的,也许对你来说没有必要。

theMovie = [[MPMoviePlayerController alloc] initWithContentURL:
    [NSURL fileURLWithPath: [[NSBundle mainBundle] 
    pathForResource"yourmovie" ofType"m4v"]]];

theMovie.view.frame = CGRectMake(0, 0, 320, 480);
[theMovie setControlStyle:MPMovieControlStyleNone];
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selectorselector(moviePlayBackDidFinish 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:theMovie];
[self.view addSubview:theMovie.view];    
[theMovie play];

关于iphone - ios MPMoviePlayerController 无法在模拟器上播放本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16340021/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4