MPMoviePlayerController起始图像
在我的应用程序中,我创build的MPMoviePlayerController
的实例作为一个黑盒子开始,看起来像这样(因为video开始黑和淡入):
不过,我正在设想一些更像用户友好的东西,像下面的例子那样有一个缩略图:
这是我创build的样机,但在消息应用程序中发送的video和video使用播放箭头。 我需要使用什么类来使用股票iOS播放箭头?
这看起来像thumbnailImageAtTime:timeOption:
的thumbnailImageAtTime:timeOption:
方法,你应该通过你想要检索缩略图的时间,并使用该图像在video顶部显示UIImageView
。
一旦你有你的缩略图,你创build一个UIImageView
并将图像设置为缩略图,并确保您将userInteractionsEnabled
设置为YES
。 确保将此图像视图的框架设置为覆盖电影播放器。
现在你可以在该图像视图上创build一个UITapGestureRecognizer
,它将触发一个方法。 这个方法然后调用你的MPMoviePlayerController
对象的play
方法。
-(void)viewDidLoad{ [...] UIImage *thumbnail = [moviePlayer thumbnailImageAtTime:5.0 timeOption:MPMovieTimeOptionNearestKeyFrame]; UIImageView *iv = [[UIImageView alloc] initWithImage:thumbnail]; iv.userInteractionEnabled = YES; iv.frame = moviePlayer.frame; [self.view addSubview:iv]; [iv release]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; tap.numberOfTapsRequired = 1; [iv addGestureRecognizer:tap]; [tap release]; [...] } - (void)handleTap:(UITapGestureRecognizer *)gesture{ iv.hidden = YES; [moviePlayer play]; }
请注意,如果您想要播放button,然后在Photoshop中制作播放button,并将其添加到缩略图图像视图顶部,请将手势识别器附加到该图像视图,并确保在开始播放video时隐藏两个图像视图。
您可以使用UIButton
,而将图像设置为播放图像,则根本不需要UIGestureRecognizer
。
您将通过将videoembedded到Web视图中的HTML 5 <video>
标记中来获取此箭头。
对于实际的实现,请参阅这样的答案使用HTML5在UIWebView中播放embedded的video 。
那么使用UIButton呢? 它可以有一个很好的背景图像,点击它,并将其移动到电影播放器的后面或者移除button。 即使在代码中添加也很简单