如何使用iOS中的RTMP为Facebook,Youtube等多种社交媒体创建实时流媒体

问题描述 投票:0回答:1

我使用LFLivekit为facebook这样的单一平台进行了直播。当我尝试两个平台时,它没有发生。

码:

import UIKit
import LFLiveKit

class VideoViewController: UIViewController {

var sessionO: LFLiveSession =
    {
        let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration(for: LFLiveAudioQuality.high)
        let videoConfiguration = LFLiveVideoConfiguration.defaultConfiguration(for: LFLiveVideoQuality.low3)
        let session = LFLiveSession(audioConfiguration: audioConfiguration, videoConfiguration: videoConfiguration)
        return session!
    }()


    override func viewDidLoad() {
        super.viewDidLoad()
        self.streamUrl = "live-api-s.facebook.com:80/rtmp/"
        self.streamName = "17XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

        self.sessionO.delegate = self
        self.sessionO.preView = self.view
        self.sessionO.running = true
    }

    override func viewDidAppear(_ animated: Bool)
    {
        super.viewDidAppear(animated)
        let stream = LFLiveStreamInfo()
        stream.url = "rtmp://\(self.streamUrl!)/LiveApp/\(self.streamName!)"
        self.sessionO.startLive(stream)
}
}

注意:如果我再为youtube创建一个会话和流,则它无效。

ios swift rtmp live-streaming youtube-livestreaming-api
1个回答
0
投票

我们需要创建单独的RTMP连接并创建监听器。

fbRtmpStream = RTMPStream(connection: fbRtmpConnection)
ytRtmpStream = RTMPStream(connection: ytRtmpConnection)

self.fbRtmpConnection1.addEventListener(Event.RTMP_STATUS, selector:#selector(self.fbRtmpStatusHandler1(_:)), observer: self)
        self.fbRtmpConnection1.connect("rtmp://live-api-s.facebook.com:80/rtmp/")
        self.fbStreamName1 = "xxxxxx"

self.ytRtmpConnection.addEventListener(Event.RTMP_STATUS, selector:#selector(self.ytRtmpStatusHandler(_:)), observer: self)
        self.ytRtmpConnection.connect("rtmp://a.rtmp.youtube.com/live2/LiveApp/")
        self.ytStreamName = "xxxxxxxxx"
© www.soinside.com 2019 - 2024. All rights reserved.