如何在ios中播放video播放器

我希望能够点击tableview项目和播放video.so我写了一些video播放器的代码。我正在使用MPMediaplayer framework.I使用jsonparsing器。使用jsonparsing器从web服务器检索数据。 我的问题是,当用户点击一个UITableView单元格是video播放器打开全屏,它只是说“加载…”的整个时间和video不加载,没有错误报告在debugging器。请帮助我任何机构..提前感谢。

-(void)viewDidLoad { urlsArray=[NSMutableArray alloc]init]; } -(void)loadData { url=[NSURL URLWithString:@"urls”]; NSMutableURLRequest *request=[[NSMutableURLRequest alloc]initWithURL:url]; [[NSURLConnection alloc]initWithRequest:request delegate:self]; [UIApplication sharedApplication].networkActivityIndicatorVisible=YES; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection { [UIApplication sharedApplication].networkActivityIndicatorVisible=NO; NSError *jsonError = nil; id jsonObject = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&jsonError]; if ([jsonObject isKindOfClass:[NSArray class]]) { } else if ([jsonObject isKindOfClass:[NSDictionary class]]) { NSDictionary *jsonDictionary = (NSDictionary *)jsonObject; NSArray *array=[[NSArray alloc]init]; array=[jsonDictionary objectForKey:@"video-urls"]; dataDictionary=[array objectAtIndex:0]; NSLog(@"%@",dataDictionary); } [urlsArray addObject:[dataDictionary objectForKey:@“Key1”]]; [urlsArray addObject:[dataDictionary objectForKey:@“Key2”]]; [urlsArray addObject:[dataDictionary objectForKey:@“Key3”]]; [urlsArray addObject:[dataDictionary objectForKey:@“Key4”]]; [urlsArray addObject:[dataDictionary objectForKey:@“Key6”]]; NSLog(@"%@",urlsArray); } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { selectedIndex=indexPath.row; NSLog(@"%@ %d",urlsArray,selectedIndex); NSString *currentUrlsArr=[urlsArray objectAtIndex:indexPath.row]; NSURL *urlString=[NSURL URLWithString:currentUrlsArr]; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:urlString]; [self.view addSubview:moviePlayer.view]; moviePlayer.fullscreen = YES; [moviePlayer play]; [tableView deselectRowAtIndexPath:indexPath animated:YES]; } 

您不设置电影播放器​​视图的框架。 正如苹果展示的那样 :

 MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL]; [player prepareToPlay]; [player.view setFrame: myView.bounds]; // player's frame must match parent's [myView addSubview: player.view]; // ... [player play]; 

这是问题

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:urlString];

之后你错过了这个方法来打电话

 [moviePlayer prepareToPlay];