2

I want to show custom video player. Video Play successfully but controls do not show. How to show the controls as play/pause button, slider, time etc.

let url = fileManager.appending(videoFileNames + ".MOV")
try!AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: [])
let player = AVPlayer(url: NSURL(fileURLWithPath: url) as URL)
let avPlayerLayer:AVPlayerLayer = AVPlayerLayer(player: player)
avPlayerLayer.frame = videoPlayerView.bounds
self.videoPlayerView.layer.addSublayer(avPlayerLayer)
player.play()
Dilan
  • 2,610
  • 7
  • 23
  • 33
Shahbaz Akram
  • 1,598
  • 3
  • 28
  • 45
  • Possible duplicate of [Setting Slider Value to Set SeekToTime in AVPlayer](http://stackoverflow.com/questions/34464643/setting-slider-value-to-set-seektotime-in-avplayer) – shallowThought Jan 19 '17 at 07:36

1 Answers1

2

AVPlayer don't show Controls by default ,we need to add buttons and slider and we need to call play , pause events on AVPlayer on that button actions as like as we need to add slider for progress by using seek function on AVPlayer.

or we can achieve by using 'AVPlayerViewController' How to play video with AVPlayerViewController (AVKit) in Swift but we need set true for showsPlaybackControls

showsPlaybackControls = true
Community
  • 1
  • 1
Satyanarayana
  • 1,059
  • 6
  • 16
  • let avpController = AVPlayerViewController() let player = AVPlayer(url: NSURL(fileURLWithPath: url) as URL) avpController.player = player //AVPlayer.init(url: urlVideoFile) avpController.view.frame = self.videoPlayerView.bounds avpController.showsPlaybackControls = false self.videoPlayerView.addSubview(avpController.view) self.videoPlayerView.autoresizesSubviews = true avpController.player?.play() – Shahbaz Akram Jan 19 '17 at 06:44
  • i implement this but video do not show? what is wrong in this code. – Shahbaz Akram Jan 19 '17 at 06:44
  • Sorry i implemet it in wrong place. Now it is working fine thanks. – Shahbaz Akram Jan 19 '17 at 06:51