MPMoviePlayerController添加自定义播放button

目前我正在一个iPhone应用程序正在显示video。 我已经使用MPMoviePlayController从本地文件夹加载video。

我们可以自定义标准媒体播放器吗? 我想要做的就是隐藏所有的标准元素(播放,转发,倒带,完成),只是用一个自定义图像的单个播放button来构build播放器。 有谁能够帮助我 ?

您当然可以为MPMoviePlayerController添加自定义控件。 首先隐藏现有的控件,使用MPMovieControlStyle ,将其设置为MPMovieControlStyleNone

现在添加自定义控件button,并在那里处理所有的MoviePlayer事件,比如;

  • 暂停
  • 停止
  • 上一页
  • 接下来等等
  • 或者您可以添加自己的控件,如跳到这个时间(+10秒,+20秒),电影速度控制(1x,2x,..)等

希望这对你有用。

如果你想有任何controlStyle的苹果,并仍然想在电影视图上添加一些自定义button。 您可以inheritanceMPMoviePlayerViewController。

假设您将MyCustomMoviePlayerViewController作为MPMoviePlayerViewController的子类,然后在MyCustomMoviePlayerViewController.m

- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchUpInside]; [button setTitle:@"MyCustomButton" forState:UIControlStateNormal]; button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); [self.view addSubview :button]; }