Search code examples
swiftvlc

Swift MobileVLCKit how to set UserAgent?


I want to set custom User Agent in the video player app using MobileVLCKit. But I am not sure how to set it in version 3.3.16. If anyone had a experience in it, please let me know. Thank you.


Solution

  • I found the solution for that.

    let vlcPlayer: VLCMediaPlayer =
    {
        let player = VLCMediaPlayer()
        return player
    }()
    let user_agent = "Your user agent"
    
    guard let url = URL(string: "video_url") else { return }
    let vlcMedia = vlcMedia(url: url)
    vlcMedia.addOption(":http-user-agent=\(user_agent)") // add here
    vlcPlayer.media = vlcMedia
    vlcPlayer.drawable = player_view
    vlcPlayer.delegate = self
    vlcPlayer.play()
    

    We can add any options in https://wiki.videolan.org/VLC_command-line_help by using addOption function.