skip to Main Content

I am trying to play an 30 seconds rtsp video in an ios app build in xcode 12.5. Unfortunately i could not find a way to do this. Could anyone give me a plugin or a way to handle this?

Thanks in advance,
Patrick

2

Answers


  1. Try VLCKit/MobileVLCKit for this task.

    Login or Signup to reply.
  2. Ok this is kinda old question, but I also found this issue, and there is not too much data out there…

    As Dmytro pointed out MobileVLCKit is the best option out there.

    I implemented it using swiftui for the interface, so firstly I have to create a UIViewRepresentable to display the stream view

    Firstly import MobileVLCKit

    struct VlcPlayerRepresentable: UIViewRepresentable{ //MARK: Transform from a UIView into swiftUI compatible
    func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<VlcPlayerRepresentable>) {
    }
    
    func makeUIView(context: Context) -> UIView {
        return PlayerUIView(frame: .zero)
    }}
    

    Then initiate the Player

    class PlayerUIView: UIView, VLCMediaPlayerDelegate,ObservableObject{
    let mediaPlayer : VLCMediaPlayer = VLCMediaPlayer()// You can also add options in here
    override init(frame: CGRect) {
        super.init(frame: UIScreen.screens[0].bounds)
        let url = URL(string: "rtsp://rtspURLString:8554/live")!//replace your resource here
        
        let media = VLCMedia(url: url)
            
        media.addOptions([// Add options here
            "network-caching": 300,
            "--rtsp-frame-buffer-size":100,
            "--vout": "ios",
            "--glconv" : "glconv_cvpx",
            "--rtsp-caching=": 150,
            "--tcp-caching=": 150,
            "--realrtsp-caching=": 150,
            "--h264-fps": 20.0,
            "--mms-timeout": 60000
        ])
        
        mediaPlayer.media = media
        mediaPlayer.delegate = self
        mediaPlayer.drawable = self
        mediaPlayer.audio.isMuted = true
       
        mediaPlayer.videoAspectRatio = UnsafeMutablePointer<Int8>(mutating: ("16:9" as NSString).utf8String)
        mediaPlayer.play()}
    
    
    func checkConnection() -> Bool{
        let isPlaying: Bool = mediaPlayer.isPlaying
        return isPlaying
    }
    
      required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
      }
    
    
      override func layoutSubviews() {
        super.layoutSubviews()
      }}
    

    And then just add the representable view to a structure, now you can add this structure to wherever you want to display the stream.

    struct VideoViewStructure: View {
    var body: some View {
        return VStack{
            VlcPlayerRepresentable()
        }
    }}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search