I want to use the control bar when playing video on swift3.

Asked 1 years ago, Updated 1 years ago, 39 views

I'm playing video on swift3.I would like to display the default control bar and seek it, but I tried to move the sample code like the one below.
I can't display the control bar even if I tap the video.Do you need any parameters?
Please let me know if you know.

let videoURL=NSURL (string: "
") let player = AVPlayer (url:videoURL!asURL) let playerLayer = AVPlayerLayer(player:player) playerLayer.frame=self.view.bounds self.view.layer.addSublayer(playerLayer) player.play()

swift

2022-09-30 21:23

1 Answers

The AVPlayer class on iOS is what MVC calls the Controller element, and does not include View elements such as a display screen (AVPlayerLayer for your code) or a control bar with playback buttons.

If the system standard control bar is acceptable, it should be used in conjunction with the AVPlayerViewController instead of the AVPlayer alone.

let videoURL=URL (string: "
")! let player = AVPlayer (url:videoURL) letplayerVC = AVPlayerViewController() playerVC.player=player player.play() present(playerVC, animated:true, completion:nil)

AVPlayerViewController can also be placed on the storyboard (the AVKit Player View Controller appears on the storyboard editor), so there are many variations in fine writing, but if you search AVPlayerViewController, you can find many articles in Japanese.


2022-09-30 21:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.