我一直在尝试播放mp4文件,我从服务器接收网址,我已经将其提供给MPMoviePlayerController,播放器正在加载,但文件没有播放。这是代码......
NSURL *url = [NSURL URLWithString:obj->msg_url]; // obj->url is a html php url not a direct file url.
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
所以在这种情况下如何使用MPMoviePlayerController从html url播放。有什么想法吗?
感谢
答案 0 :(得分:0)
尝试
[moviePlayer play];
看起来应该不会总是产生预期效果。
答案 1 :(得分:0)
我先下载并立即开始工作。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"sample.mp4"];
[urlData writeToFile:filePath atomically:YES];
NSURL *file_url = [NSURL fileURLWithPath:filePath];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:file_url];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];