gpt4 book ai didi

ios - 使用 YOUTUBE urls 如何在 ios 中播放视频播放器

转载 作者:行者123 更新时间:2023-11-29 12:47:10 25 4
gpt4 key购买 nike

<分区>

我希望能够点击表格 View 项目并播放视频。我正在尝试使用 MPMoviePlayerController 流式传输一些 YouTube 视频,但我遇到了一些问题。我正在使用 json 解析器从网络服务器检索数据。我的问题是,当用户点击 UITableViewCell 时,视频播放器会全屏打开,并且一直显示“正在加载...”并且视频不会加载,也不会报告任何错误在调试器中。

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

NSLog(@"urlstring %@",currentUrlsArr);

NSString *youTubeString=[[NSString alloc]initWithFormat:@"https://www.youtube.com/watch?v="];

NSString *stringAppend=[youTubeString stringByAppendingString:currentUrlsArr];

stringAppend =[stringAppend stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

NSURL *urlString=[NSURL URLWithString:stringAppend];

NSLog(@"%@",urlString);

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

[self.view addSubview:moviePlayer.view];

moviePlayer.shouldAutoplay=YES;

[moviePlayer prepareToPlay];

moviePlayer.fullscreen = YES;

[moviePlayer play];

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com