I am using MPMoviePlayerController
to play videos in my app. Now I need to add some custom buttons like "Next Track" or "Previous Track" and remove some unwanted buttons-
After adding buttons, I have to provide actions for each button.
How can I achieve this in swift?
func Player(url :NSURL){
moviePlayer = MPMoviePlayerController(contentURL: url)
self.view.addSubview(moviePlayer.view)
moviePlayer.fullscreen = true
moviePlayer.controlStyle = MPMovieControlStyle.Fullscreen
}
It is definitely possible to add custom controls for MPMoviePlayerController. Since you want to hide some of them, it would be actually easier for you to recreate all of them so your UI will fit. First, hide default controls:
player.controlStyle = MPMovieControlStyle.None
I would suggest then to subclass MPMoviePlayerController and make your own class, that will create your own controls, like this:
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)
}
}
Then, instead of using regular MPMoviePlayerController, just use your custom one!
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With