Ios 如何将视频添加到tableview?
在我的应用程序中,我想在tableview的后续行中显示视频。视频将从一个JSON服务中获取,该服务采用字符串格式。我们如何才能做到这一点。任何帮助都将不胜感激。如果您想使用GET从服务器获取响应(视频),您可以尝试以下方法Ios 如何将视频添加到tableview?,ios,Ios,在我的应用程序中,我想在tableview的后续行中显示视频。视频将从一个JSON服务中获取,该服务采用字符串格式。我们如何才能做到这一点。任何帮助都将不胜感激。如果您想使用GET从服务器获取响应(视频),您可以尝试以下方法 //just give your URL instead of my URL NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithS
//just give your URL instead of my URL
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://api.worldweatheronline.com/free/v1/search.ashx?query=London&num_of_results=3&format=json&key=xkq544hkar4m69qujdgujn7w"]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
//You need to check response.Once you get the response copy that and paste in ONLINE JSON VIEWER.If you do this clearly you can get the correct results.
//After that it depends upon the json format whether it is DICTIONARY or ARRAY
//If it is Dictionary
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error: &err];
or
//If it is Array
NSMutableArray *json=[NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];
NSMutableArray *imgvd=[[NSMutableArray alloc]init];
for (int i =0 ; i<json.count; i++)
{
NSString *dd =[[json objectAtIndex:i]objectForKey:@"url"];
NSString *pp = [[json objectAtIndex:i]objectForKey:@"title"];
vedios *myvd = [[vedios alloc]initWithvideo:dd andtitle:pp];
[imgvd addObject:myvd];
}
//只需给出您的URL而不是我的URL
NSMutableURLRequest*请求=[NSMutableUrlRequestRequestWithURL:[NSURL URLWithString:@]http://api.worldweatheronline.com/free/v1/search.ashx?query=London&num_of_results=3&format=json&key=xkq544hkar4m69qujdgujn7w"]];
[请求设置HttpMethod:@“获取”];
[request setValue:@“application/json;charset=UTF-8”forHTTPHeaderField:@“content type”];
n错误*错误;
NSURLResponse*响应;
NSData*responseData=[NSURLConnection sendSynchronousRequest:request ReturnInResponse:&响应错误:&错误];
//您需要检查响应。一旦收到响应,请将其复制并粘贴到在线JSON查看器中。如果您清楚地这样做,您可以得到正确的结果。
//之后,它取决于json格式是字典还是数组
//如果是字典
NSDictionary*jsonArray=[NSJSONSerialization JSONObjectWithData:responseData选项:NSJSONReadingMutableContainers错误:&err];
或
//如果是数组
NSMutableArray*json=[NSJSONSerialization JSONObjectWithData:responseData选项:针状体错误:nil];
NSMutableArray*imgvd=[[NSMutableArray alloc]init];
对于(int i=0;i)如果您想了解更多有关您自己试图解决此问题的信息,我们将无法帮助您。请阅读.NSString*videoLink=[dict objectForKey:@“Video”];NSLog(@“%@”,videoLink);NSURL*videoURL1=[NSURL alloc]init];videoURL1=(NSURL*)videoLink;NSLog(@“%@”,videoURL1);MPMoviePlayerController*player=[[MPMoviePlayerController alloc]initWithContentURL:videoURL1];UIImage*imageSel=[player ThumbnailImageTime:1.0时间选项:MPMovieTimeOptionAresTkeyframe];[player停止];当video1获取此VMS1403002649476.MP4的值时,tableviewcells的出列机制将使您的应用程序不可靠。实际上,它是新闻提要,将显示在tableview中,就像facebook@HaneTVI知道如何获取视频一样,但我需要使用这是MPMoviePlayerController*播放器在表视图行中显示它=[[MPMoviePlayerController alloc]initWithContentURL:videoURL1];UIImage*imageSel=[player thumbnailImageAtTime:1.0时间选项:MPMovieTimeOptionAresTkeyframe];[player stop];给出错误。-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{静态NSString*cellIdentifier=@“Cell”;vediopoliticalCell*cell=(vediopoliticalCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];if(cell==nil){cell=[[VediopoliticalCellAlloc]initWithStyle:UtiableViewCellStyleDefault reuseIdentifier:cellIdentifier];}[cell setDataSource:[imgvd objectAtIndex:Indexath.row]];NSLog(@“数据%@),[imgvd objectAtIndex:indexath.row]);返回单元格;}只需在上面的cellForRowAtIndexPath中给出编码,就像在tableview数据源委托方法中那样。