Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play rtmp link in avplayer?

I'm trying to play rtmp link in avplayer. However it's not playing. What should I do?

self.avAsset = AVAsset(URL: NSURL(string: rtmpUrlString)!)

Thanks.

like image 648
Murat Kaya Avatar asked Jun 03 '16 19:06

Murat Kaya


1 Answers

AVPlayer doesn't support RTMP streaming.

The easiest way to play RTMP stream on iOS devices is play it via VLCKit.

  1. add pod 'MobileVLCKit-unstable', '3.0.0a23' to your podfile.

  2. run pod install to install it.

  3. add #import <MobileVLCKit/MobileVLCKit.h> in your bridging header file to make this framework available in Swift

  4. in your view controller initiate VLC Media Player and start playing stream:

    var player: VLCMediaPlayer!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        player = VLCMediaPlayer()
        player.media = VLCMedia(url: URL(string: "rtmp://сс.tv/sea")!)
        player.drawable = view
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if !player.isPlaying {
            player.play()
        }
    }
    
like image 55
Max Potapov Avatar answered Oct 04 '22 11:10

Max Potapov