我在播放基于 URL 的视频时遇到问题。这是我的代码:
-(void)clickplay
{
NSURL *fileURL = [NSURL URLWithString:@"http://km.support.apple.com/library/APPLE/APPLECARE_ALLGEOS/HT1211/sample_iTunes.mov"];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc]initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
它编译成功,播放器确实弹出了,但它只是一直在加载……我尝试多次更改 URL,但没有效果。谁能帮我解决这个问题?
最佳答案
您需要保留对 moviePlayerController 的引用。它正在被释放并阻止调用任何委托(delegate)消息。可能最简单的放置位置是在包含 - (void)clickplay
的类中。执行。也就是说,添加一个名为 moviePlayerController
的新实例变量。并为其分配新创建的MPMoviePlayerController
clickplay
中的对象.
关于objective-c - 无法从 iPhone 应用程序中的 URL 播放视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12920399/