如何在iOS中播放视频播放器[英] How to play video player in ios

本文是小编为大家收集整理的关于如何在iOS中播放视频播放器的处理方法,想解了如何在iOS中播放视频播放器的问题怎么解决?如何在iOS中播放视频播放器问题的解决办法?那么可以参考本文帮助大家快速定位并解决问题。

问题描述

我希望能够单击 tableview 项目并播放视频.所以我为视频播放器编写了一些代码.我正在使用 MPMediaplayer 框架.我正在使用 json 解析器.使用 json 解析器从中检索数据网络服务器.我的问题是,当用户单击 UITableView 单元格时,视频播放器会全屏打开,并且一直说"正在加载..."并且视频没有加载,调试器中也没有报告错误.请帮助我的任何身体..提前谢谢.

-(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];
}

推荐答案

问题来了

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

在这之后你错过了这个方法来调用

[moviePlayer prepareToPlay];

本文地址:https://www.itbaoku.cn/post/924627.html

相关标签/搜索