我正在使用MPMoviePlayerController在我的应用程序中播放视频.现在我需要添加一些自定义按钮,如“下一曲”或“上一曲”,并删除一些不需要的按钮 –
添加按钮后,我必须为每个按钮提供操作.
如何快速实现?
func Player(url :NSURL){ moviePlayer = MPMoviePlayerController(contentURL: url) self.view.addSubview(moviePlayer.view) moviePlayer.fullscreen = true moviePlayer.controlStyle = MPMovieControlStyle.Fullscreen }
解决方法
绝对有可能为MPMoviePlayerController添加自定义控件.由于您想要隐藏其中的一些,因此您将更容易重新创建所有这些,以便您的UI将适合.首先,隐藏默认控件:
player.controlStyle = MPMovieControlStyle.None
我会建议然后继承MPMoviePlayerController,并自己创建类,这将创建您自己的控件,如下所示:
class Player : MPMoviePlayerController { // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- // MARK: - Setup override func viewDidLoad() { // Don't forget to call super super.viewDidLoad() // Setup your UI self.setupCustomControls() } func setupCustomControls() { // Create buttons,labels etc. here let button = UIButton(frame: CGRectZero) self.view.addSubview(button) } }
然后,而不是使用常规的MPMoviePlayerController,只需使用您的自定义的!
希望有帮助!