Skip to content

[iOS] rtsp stops after a few seconds

I'd like to ask you a question. I've integrated MobileVLCKit on my iOS project.

I'm streaming a RTSP from my camera. the URI may look like this: rtsp://192.168.0.1:554/livestream/5

My problem is that the player plays only for first few seconds. Then it (stops) freezes the stream.

I'm not sure of what is going on is a bug or not. Please help how I can resolve it

Thank you very much. The following is a snippet of code

import UIKit
import AVFoundation
import AVKit

class ViewController: UIViewController, VLCMediaPlayerDelegate {

    var movieView: UIView!

    var mediaPlayer: VLCMediaPlayer = VLCMediaPlayer(options: ["--codec=avcodec"])

    override func viewDidLoad() {
        super.viewDidLoad()
        setUpVLC()
        
    }
    
    func setUpVLC() -> Void {
        
        //Setup movieView
        self.movieView = UIView()
        self.movieView.backgroundColor = UIColor.gray
        self.movieView.frame = UIScreen.screens[0].bounds
        
        
        //Add movieView to view controller
        self.view.addSubview(self.movieView)
        

        // Playing RTSP from internet
        let url = URL(string: "rtsp://192.168.0.1:554/livestream/5")
        
        if url == nil {
            print("Invalid URL")
            return
        }
        
        mediaPlayer.libraryInstance.debugLogging = true
        mediaPlayer.libraryInstance.debugLoggingLevel = 3

        
        let media = VLCMedia(url: url!)
        
        // Set media options
        // https://wiki.videolan.org/VLC_command-line_help
        media.addOptions([
            "network-caching": 300
        ])
        
        mediaPlayer.media = media
        
        mediaPlayer.delegate = self
        mediaPlayer.drawable = self.movieView
        mediaPlayer.play()
    }
    
    func mediaPlayerStateChanged(_ aNotification: Notification!) {
    }
    
    func mediaPlayerTimeChanged(_ aNotification: Notification!) {

    }
    
    func mediaPlayerTitleChanged(_ aNotification: Notification!) {
    }
    
    func mediaPlayerChapterChanged(_ aNotification: Notification!) {
    }
    
    func mediaPlayerSnapshot(_ aNotification: Notification!) {
    }
}
Edited by Jean-Baptiste Kempf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information