Ios MPMoviePlayerController赢得';t打开
我正在制作一个带有splitviewcontroller的应用程序,想播放一段视频 我在分割视图中有两个控制器。 左(主)为Ios MPMoviePlayerController赢得';t打开,ios,objective-c,ipad,mpmovieplayercontroller,uisplitviewcontroller,Ios,Objective C,Ipad,Mpmovieplayercontroller,Uisplitviewcontroller,我正在制作一个带有splitviewcontroller的应用程序,想播放一段视频 我在分割视图中有两个控制器。 左(主)为VideoMenuTableViewController 右侧(细节)为VideoViewController 首先,我将代码放入VideoViewController的viewdidload中,测试视频是否正常工作 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
VideoMenuTableViewController
右侧(细节)为VideoViewController
首先,我将代码放入VideoViewController
的viewdidload
中,测试视频是否正常工作
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *SelectedUrl;
SelectedUrl = [[[self.dataSource.videos valueForKey:@"URL"] objectAtIndex:0] objectAtIndex:indexPath.row];
NSLog(@"URL pressed %@",SelectedUrl);
VideosViewController *vvc = [[VideosViewController alloc] init];
vvc.URLForVideoFile = SelectedUrl;
[vvc PlayMovieFromSelectedUrl];
}
像这样:
- (void)viewDidLoad
{
[super viewDidLoad];
self.URLForVideoFile = @"http://api.smit-it.info/TEST/VIDEO/two.mov";
NSURL *fileURL = [NSURL URLWithString:self.URLForVideoFile];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[self presentMoviePlayerViewControllerAnimated:mp];
}
这样可以工作,视频也可以播放
现在,我试图通过触摸视频菜单TableViewController
中的标题来打开视频
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *SelectedUrl;
SelectedUrl = [[[self.dataSource.videos valueForKey:@"URL"] objectAtIndex:0] objectAtIndex:indexPath.row];
NSLog(@"URL pressed %@",SelectedUrl);
VideosViewController *vvc = [[VideosViewController alloc] init];
vvc.URLForVideoFile = SelectedUrl;
[vvc PlayMovieFromSelectedUrl];
}
其中PlayMovieFromSelectedUrl
与viewdidload
应用程序崩溃并出现以下错误
Warning: Attempt to present <MPMoviePlayerViewController: 0xb25c440>
on <VideosViewController: 0xb2565d0> whose view is not in the window
hierarchy!
视频播放,但当视频完成或取消时,分割视图停止响应所有内容。在.h文件中分配MPMoviePlayerViewController*mp。 错误表明:您的VideosViewController不在窗口层次结构中。这意味着窗口管理器不知道
vvc
VideosViewController的存在。您必须告诉应用程序您实际上想要显示vvc
。试着这样做:
...
VideosViewController *vvc = [[VideosViewController alloc] init];
vvc.URLForVideoFile = SelectedUrl;
UIWindow* keyWindow= [[UIApplication sharedApplication] keyWindow];
[keyWindow addSubview: vvc.view];
[self presentViewController:vvc animated:NO completion:nil];
[vvc PlayMovieFromSelectedUrl];
....
您可以在didSelectRowAtIndexPath中调用此方法PlayMovieFromSelectedUrl,[self PlayMovieFromSelectedUrl]或者在VideosView控件viewDidLoad方法中调用此方法。我添加了3行代码,效果良好。谢谢你的帮助。我现在面临一个新的问题,即视频完成后UI无法正常工作/冻结。