Skip to content

VLCMediaPlayer crashes sometimes by stop() und dealloc the UIViewController, what contents the player

The error happens in master-branch. The error does not happen in 3.3.9-branch/tag I have a theory that it's related to the commit.

media player: remove no longer needed assert 99e057d4

Example

  1. I have a list of the Urls
  2. With every tap on the URL, i open MyPlayerViewController with presentViewConroller, and start playing with play-Method
  3. With closeButton i dismiss MyPlayerViewController

class MyPlayerViewController : UIViewController {

private let vlcVideoView = UIView(frame: .zero)
private let vlcMediaPlayer: VLCMediaPlayer = VLCMediaPlayer()

//  Button to dismiss the MyPlayerViewController
private let closeButton = UIButton(type: .system)

override func viewDidLoad() {
    super.viewDidLoad()
    
    self.vlcMediaPlayer.drawable = vlcVideoView
    //  add vlcVideoView to view hierarchy
    
    self.closeButton.addTarget(self, action: #selector(MyPlayerViewController.close(_:)), for: .touchUpInside)
   //  add closeButton to view hierarchy
}

public func play(url: String) {
    guard let url = URL(string: url) else {
        return
    }
    
    let media = VLCMedia(url: url)
    self.vlcMediaPlayer.media = media
    self.vlcMediaPlayer.play()
}

public func play() {
    self.vlcMediaPlayer.play()
}

public func stop() {
    if self.vlcMediaPlayer.isPlaying {
        self.vlcMediaPlayer.stop()
    }
}

public func pause() {
    self.vlcMediaPlayer.pause()
}

//  when stopping, the UI freezes, and sometimes sporadically the app crashes with cryptic asserts
//  in branch/tag 3.3.9 this does not happen.
@objc func close(_ sender: UIButton) {
    self.stop()
    dismiss(animated: true, completion: nil)
}

}

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information