MPMoviePlayerController启动图像 [英] MPMoviePlayerController starting image
问题描述
在我的应用程序中,我创建的 MPMoviePlayerController
的实例以黑框开头,看起来像这样(因为视频以黑色开始淡入淡出):
In my app the instance of MPMoviePlayerController
I created starts out as a black box, looking like this (because the video starts out black and fades in):
然而,我想象一下像这样的用户友好的东西,带有缩略图,如下例所示:
However I was envisioning something more user-friendly like this, with a thumbnail image, like the example below:
这是我创建的模型,但是相片中的视频在消息应用中发送的视频使用该播放箭头。使用iOS播放箭头需要实现哪个类?
That's a mockup I created but videos in the cameral roll and videos sent in the Messages app use that play arrow. What class do I need to implement to use the stock iOS play arrow?
推荐答案
这看起来像是 thumbnailImageAtTime:timeOption:
MPMoviePlayerController
的方法,您应该传入要检索缩略图的时间并使用该图像来显示在视频之上 UIImageView
。
This looks like something for the thumbnailImageAtTime:timeOption:
method of MPMoviePlayerController
, you should pass in the time you want to retrieve a thumbnail for and use that image to display a UIImageView
on top of the video.
获得缩略图后,您可以创建 UIImageView
并将图像设置为缩略图,并确保设置 userInteractionsEnabled
到是
。确保将此图像视图的边框设置为覆盖电影播放器。
Once you have your thumbnail you create a UIImageView
and set the image to the thumbnail and make sure you set userInteractionsEnabled
to YES
. Make sure to set the frame of this image view to cover the movie player.
现在您可以创建 UITapGestureRecognizer
在该图像视图上将触发一个方法。然后,此方法调用 MPMoviePlayerController
对象的 play
方法。
Now you can create a UITapGestureRecognizer
on that image view which will trigger a method. This method then invokes the play
method of your MPMoviePlayerController
object.
-(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];
}
请注意,如果你想要播放按钮,那么在Photoshop中制作播放按钮,并将其添加到缩略图图像视图的顶部,将手势识别器附加到该图像视图,并确保在开始播放视频时隐藏两个图像视图。
Please note if you want the play button then make a play button in Photoshop, and add this on top of the thumbnail image view, attach the gesture recognizer to that image view and make sure you hide both image views when you start playing your video.
您可以使用 UIButton
,否则将图像设置为播放图像,那么根本不需要 UIGestureRecognizer
。
You could use a UIButton
otherwise with the image set to the play image, then you wouldn't need a UIGestureRecognizer
at all.
这篇关于MPMoviePlayerController启动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!