【发布时间】:2014-08-08 18:00:30
【问题描述】:
我有一个 ICarousel 可以正确显示我的所有视频,但是当我按下播放按钮时,它会在下一个索引而不是我所在的索引上播放视频。
我希望它在指定的索引处播放,我尝试将[sender tag] 作为索引传递,并尝试一些技巧以在该索引处创建具有适当播放项的另一个子视图。
似乎没有任何效果,这是什么原因?!!
这是我的viewForItemAtIndex
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:[_videoURLS objectAtIndex:index]] options:nil];
//Video Player View
_videoView = [[UIView alloc] initWithFrame:CGRectMake(0,0, mainViewWidth, 220)];
_videoView.backgroundColor = [UIColor colorWithRed:123/255.0 green:123/255.0 blue:123/255.0 alpha:1.0];
_videoView.center = CGPointMake(100, 170);//170
_videoView.tag = 20;
[view addSubview:_videoView];
//Play Button
_playButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60.0f, 60.0f)];
[_playButton setBackgroundImage:[UIImage imageNamed:@"play-icon-grey.png"] forState:UIControlStateNormal];
[_playButton addTarget:self action:@selector(playVideo:) forControlEvents:UIControlEventTouchUpInside];
_playButton.center = CGPointMake(100, 160);
_playButton.tag = index;
[view addSubview:_playButton];
//AV Asset Player
AVPlayerItem * playerItem = [[AVPlayerItem alloc] initWithAsset:asset];
_player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
playerLayer.frame = _videoView.bounds;
// [playerLayer setFrame:_videoView.frame];
[_videoView.layer addSublayer:playerLayer];
[_player seekToTime:kCMTimeZero];
return view;
}
这将显示甚至播放,尽管它只是不会播放当时专注的正确的。 我已经坚持了几天了,感谢任何帮助!
【问题讨论】:
-
能否提供playVideo:方法的代码。然后我们可以看到你的问题。因为在 - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 中你初始化了资产。我认为您在 playVideo: 方法中也使用了相同的代码。一件事这个问题总是来的?如果 iCarousel 视图没有滚动
-
如大家所说,请贴出playVideo方法的代码以解决您的问题
标签: ios objective-c indexing avplayer icarousel