我正在尝试实现视频网址的iCarousel,以允许用户查看其他帖子。 现在我不得不说我爱iCarousel,这是我唯一的问题。
我有正确数量的轮播对象出现,并且播放按钮在所有这些对象上,但我一次只接收一个视频而且控件没有正确播放视频。
我有一个持有_videoURLS
的NSMutableArray,这是我提供需要通过[_videoURLS count];
在我的.m文件中,这就是我如何使用轮播对象准备视频播放器
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
if (view == nil)
{
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 370.0f)];
view = mainView;
CGFloat mainViewWidth = mainView.bounds.size.width;
//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);
_videoView.tag = 7;
[view addSubview:_videoView];
//video
_player = [[MPMoviePlayerController alloc] init];
[_player.view setFrame:_videoView.bounds];
[_player prepareToPlay];
[_player setShouldAutoplay:NO];
_player.scalingMode = MPMovieScalingModeAspectFit;
_player.controlStyle = MPMovieControlStyleNone;
[_videoView addSubview:_player.view];
//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.view.superview action:@selector(postThread:) forControlEvents:UIControlEventTouchUpInside];
_playButton.center = CGPointMake(100, 160);
_playButton.tag = 3;
[view addSubview:_playButton];
}
else
{
//get a reference to the label in the recycled view
_playButton = (UIButton *) [view viewWithTag:3];
_videoView = (UIView *) [view viewWithTag:7];
}
//Setting Video For Each Carousel
for (int i = 0; i < 9; i++) {
[_player setContentURL:[NSURL URLWithString:[_videoURLS objectAtIndex:index]]];
NSLog(@"Object Link: %@",[_videoURLS objectAtIndex:index]);
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlaying:) name:MPMoviePlayerPlaybackDidFinishNotification object:_player];
return view;
}
如果我在旋转木马中有一个对象并且只能处理一个视频,它的效果非常好,我必须能够在旋转木马上处理10个视频,并且如果可能的话,在聚焦时加载它们。
从个人经验来看,我觉得这是每个项目被吸引到屏幕的方式,我只是无法理解这个问题。
非常感谢任何帮助!!
答案 0 :(得分:2)
根据苹果文档,我发现这不能完成,我选择使用AVFoundation Framework