ios - 加载 ICarousel 的 MPMovieControl 无法正常工作

标签 ios objective-c video mpmovieplayercontroller icarousel

我正在尝试实现视频 URL 的 iCarousel,以允许用户查看其他帖子。 现在我不得不说我喜欢 iCarousel,这是我唯一的问题。

我显示了正确数量的轮播对象,并且播放按钮位于所有对象上,尽管我一次只接收一个视频,并且控件无法正确播放视频。

我有一个 NSMutableArray 来保存 _videoURLS,这是我通过 [_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 个视频,如果可能的话,让它们在聚焦时加载。

根据个人经验,我觉得这将是每个项目绘制到屏幕上的方式,我只是无法弄清楚这个问题。

非常感谢任何帮助!!

最佳答案

根据苹果文档,我发现这是无法完成的,我选择使用 AVFoundation 框架

关于ios - 加载 ICarousel 的 MPMovieControl 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25108527/

相关文章:

video - 我想将图像(3~4ea)和 mp3 转换为 mp4 文件

javascript - python或JS可以隐藏视频嵌入源吗?

ios - 我们如何在 Delphi iOS 中使用 Open SSL?

ios - 将应用程序发送给多人 (2000) 进行测试,而无需进入 Apple 审批流程

ios - Swift 3 Firebase 更新代码转换 - 排序

iphone - 自定义 NSOperation 中的随机崩溃

ios - 检查 SKAction 是否正在运行

iphone - iAd 在 iPad 上不工作

objective-c - iPhone 开发 : Why does GKLeaderboard loadScoresWithCompletionHandler: return a null value

ios - iOS 上从 mov 转换为 mp4 的视频无法在浏览器等上播放