Ios 如何在用户单击tableview项目时播放视频
我希望能够单击Ios 如何在用户单击tableview项目时播放视频,ios,objective-c,Ios,Objective C,我希望能够单击tableview项并播放视频。因此我为视频播放器编写了一些代码。我使用MPMediaplayer框架。我使用json解析器。使用json解析器从webserver检索数据。我的问题是如果单击tableview第一项收到以下例外情况: 'NSRangeException',原因:'*-[\uu NSArrayM objectAtIndex:]:索引2超出空数组的界限' *** First throw call stack: (0x1ba7012 0x15f6e7e 0x1b490b
tableview
项并播放视频。因此我为视频播放器编写了一些代码。我使用MPMediaplayer
框架。我使用json解析器
。使用json解析器
从webserver检索数据。我的问题是如果单击tableview
第一项收到以下例外情况:
'NSRangeException',原因:'*-[\uu NSArrayM objectAtIndex:]:索引2超出空数组的界限'
*** First throw call stack:
(0x1ba7012 0x15f6e7e 0x1b490b4 0x1c203a8 0x1ae59 0x813285 0x8134ed 0x121d5b3 0x1b66376 0x1b65e06 0x1b4da82 0x1b4cf44 0x1b4ce1b 0x249e7e3 0x249e668 0x763ffc 0xd66d 0x3a4770d 0x1)
libc++abi.dylib: terminate called throwing an exception
这是我的密码
-(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
{
// self.selectedIndex=indexPath.row;
currentUrlsArr=[urlsArray[indexPath.row]lastPathComponent];
NSString *documentDirectoryPath= [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath=[documentDirectoryPath stringByAppendingPathComponent:currentUrlsArr];
NSURL *videoURL =[NSURL fileURLWithPath:filePath];
MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
videoPlayerView.moviePlayer.fullscreen=TRUE;
[self presentMoviePlayerViewControllerAnimated:videoPlayerView];
[videoPlayerView.moviePlayer play];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
当您的数组为空且试图从空数组中获取值时出现问题。NSLog(@“%@”,urlsArray);这行打印了什么?嗨,现在我遇到了这样的异常:local WeeklyAudioPlayerTable[1605]:CGContextSaveGState:invalid context 0x0检查此hi@mohitpopat请来到聊天室。我想根据我的问题与你聊天。请来到iPhone/ipad聊天室