【问题标题】:MPMoviePlayerViewController customizationMPMoviePlayerViewController 自定义
【发布时间】:2010-08-24 05:14:46
【问题描述】:

我正在使用 MPMoviePlayerViewController - 播放器控件设置为:MPMovieControlStyleFullscreen

我在使用 MPMovieControlStyleFullscreen 中的某些按钮时遇到问题:前进、后退和全屏(箭头指向彼此的那个)。

我想移除前进、后退和全屏按钮,或者控制用户点击它们时的操作。

谢谢!

【问题讨论】:

  • 另一个溢出用户提出的这个问题可能会让您深入了解您要完成的工作。希望这会有所帮助。 stackoverflow.com/questions/190493/…>?稍后。

标签: objective-c iphone


【解决方案1】:

无法自定义 Apple 提供的 MPMovieControlStyle 值。您需要做的是关闭 Apple 控件 (MPMovieControlStyleNone),然后创建自己的自定义控件。 Apple 可以将您自己的 UIView 放入此处的层次结构中,因此您可以像这样开始:

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: YOUR_URL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
UIView *movieView = moviePlayer.view;
[movieView addSubview: _movieControlsView];
[movieView bringSubviewToFront: _movieControlsView];

_movieControlsView 之前在代码或 IB 中设置的位置。

从美学上讲,您可以随心所欲,但我建议您坚持使用看起来像 Apple 选择的东西,以免混淆用户。对于我刚刚完成的项目,我创建了一个与电影播放器​​完全一样大小的透明按钮。单击该按钮会在底部的控制栏中使用我的自定义控件淡入淡出。如果未单击其中一个控件,则控制栏会在几秒钟后再次淡出。

【讨论】:

  • @iTroyd23 我认为 Scott 的意思是制作一个覆盖控件视图来禁用 moviePlayer 的用户交互。
【解决方案2】:

首先,MPMoviePlayerController 与 MPMoviePlayer*View*Controller 略有不同,因此在转换构建于 iOS 4.3+ 环境中的应用程序时,其中一些答案会导致问题。

我使用 MPMoviePlayerController 构建了一些应用程序,这些应用程序在 iOS 3.2 中运行良好。当我使用 XCode 3.2.6 (iOS 4.3) 重建它时,视频甚至无法在 iPhone 上播放。此后,我通过将 MPMoviePlayerController 实例添加到子视图来解决此问题,然后在 fullScreenMode 中显示带有 movplayer 的模式(播放器是 UIViewController):

//from didSelectRowAtIndexPath

Vid *selected = [items objectAtIndex:position];

player = [[Player alloc] init]; 
movplayer = [[MPMoviePlayerController alloc] initWithContentURL:selected.vidURL];
movplayer.view.frame = player.view.bounds;
movplayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | 
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

[player.view addSubview:movplayer.view];
[self presentModalViewController:player animated:YES];
[movplayer setFullscreen:YES animated:NO];
[movplayer play];
[player release];

//movplayer is released inside - (void)exitedFullscreen:(NSNotification*)notification 

这是因为 UINavigationBar 在旋转时被半截掉

当我使用 iPad 版本的应用程序时,模态选项在美学上不起作用。在全屏模式下旋转时,UISplitViewController navBar 和工具栏也被截断了一半。所以我尝试实现 MPMoviePlayerViewController 而不是 MPMoviePlayerController。通过这种转换,XCode 在尝试设置时给了我错误:

movplayer.controlStyle = MPMovieControlStyleEmbedded;

使用 MPMoviePlayerViewController 执行此操作的正确方法是:

movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;

当播放器作为子视图添加时,捏合手势将在全屏和父视图 (player.view.bounds) 的大小之间平滑切换播放器,并保留父视图原生的工具栏和导航栏。

//iPad version with a view (viewForMovie) inside the DetailViewController
movplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[current vidURL]];
movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
movplayer.view.backgroundColor = [UIColor clearColor];
movplayer.view.frame = viewForMovie.bounds;
[viewForMovie addSubview:movplayer.view];

因此,这两个示例为想要将其 iPhone 或 iPad 应用程序转换为更新的 iOS 版本的用户展示了一些解决方法。

【讨论】:

    【解决方案3】:

    尝试将MPMoviePlayerController 对象的MPMovieControlStyle 设置为MPMovieControlStyleNone

    【讨论】:

    • 唯一的问题是,如果最终用户不想观看整个视频,我需要一种方法来结束视频。
    • 您好,请告诉我您是如何做到这一点的。你自己做了控件吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多