简体   繁体   中英

How to open VLC in fullscreen mode in swift

Im using MobileVLCKit, here is my code:

class CameraViewController: UIViewController,VLCMediaPlayerDelegate{

  var mediaPlayer = VLCMediaPlayer()

  override func viewDidLoad() {
    super.viewDidLoad()

    mediaPlayer.delegate = self
    let url = NSURL(string: "URL HERE")
    mediaPlayer.media = VLCMedia(URL: url!)
  }
}  

I want to open VLC in fullscreen with play,pause and timer

Thanks,

*I found a sollution from Videolan/VLC Kit

First we've to install VLC pods

pod 'MobileVLCKit'
var mediaPlayer: VLCMediaPlayer = VLCMediaPlayer()
 func playDownload(url: URL)
 {
        self.movieView = UIView()
        self.movieView.backgroundColor = UIColor.gray
        self.movieView.frame = UIScreen.screens[0].bounds

        //Add tap gesture to movieView for play/pause
        let gesture = UITapGestureRecognizer(target: self, action: #selector(ViewController.movieViewTapped(_:)))
        self.movieView.addGestureRecognizer(gesture)

        //Add movieView to view controller
        self.view.addSubview(self.movieView)
        let media = VLCMedia(url: url)
        mediaPlayer.media = media
        mediaPlayer.delegate = self
        mediaPlayer.drawable = movieView
        mediaPlayer.play()
 }
@objc func movieViewTapped(_ sender: UITapGestureRecognizer) {
    if mediaPlayer.isPlaying 
    {
      mediaPlayer.pause()
      let remaining = mediaPlayer.remainingTime
      let time = mediaPlayer.time
      print("Paused at \(time?.stringValue ?? "nil") with \(remaining?.stringValue ?? "nil") time remaining")
    } else {
      mediaPlayer.play()
      print("Playing")
    }
}

VLCKit does not include a "fullscreen" feature. You need to set the mediaPlayer's drawable to a UIView and take care of the view handling yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM