【发布时间】:2015-02-13 05:29:02
【问题描述】:
这是我运行良好的代码。在这里,我正在访问我的 tableview 中的视频数组.....
这是我的视频数组,视频在我的捆绑包中...
- (void)viewDidLoad {
[super viewDidLoad];
videos = [[NSMutableArray alloc] initWithObjects:
@"video 1",
@"video 2",
nil];
}
在 tableview 中访问视频.....
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSIndexPath *index ;
index = [self.table indexPathForCell:cell];
NSLog(@"%@----hello",indexPath);
// taking path of video from bundle
NSString *filePath = [[NSBundle mainBundle]pathForResource:[videos objectAtIndex:indexPath.row] ofType:@"mp4"];
//declare nsurl and mpmoviplayer globally..
movieURL = [NSURL fileURLWithPath:filePath];
// <converting image in thumbnail...
AVAsset* videoAsset = [AVAsset assetWithURL:movieURL];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:videoAsset];
Float64 durationSeconds = CMTimeGetSeconds([videoAsset duration]);
CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600);
NSError* error = nil;
CMTime actualTime;
//generating image...
CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error];
// show image in uiimage of tableviewcell....
cell.imageView.image=[UIImage imageWithCGImage:halfWayImage];
cell.textLabel.text= [videos objectAtIndex:indexPath.row];
return cell;
}
通过 Segue 访问其他视图中的视频......
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetailsSeg"]) {
//playing video in other view controller....
[[player view] setFrame: self.view.frame];
[self.view addSubview: [player view]];
[self presentMoviePlayerViewControllerAnimated:player];
//using sequel for destination controller
[segue destinationViewController] ;
}
}
完成....
【问题讨论】:
-
您的视频是在服务器上还是在文档目录中?
-
如果它运行良好,你到底在问什么?
-
它在文档列表中。现在我想在 tableview 中显示视频的缩略图,它只显示视频的名称。
-
@DarshanMothreja 视频的存储名称与您在表格中显示的名称相同?
-
查看我编辑的代码。现在我想在 tableview 中显示视频的缩略图,它只显示视频名称..
标签: ios uitableview mpmovieplayercontroller