Skip to content

Commit 2952b54

Browse files
author
xianing
committed
fix macos rtmp issues
1 parent 2d969a6 commit 2952b54

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

macOS/APIExample/Examples/Advanced/RTMPStreaming/RTMPStreaming.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class RTMPStreaming: BaseViewController {
2020
var agoraKit: AgoraRtcEngineKit!
2121

2222
var transcoding = AgoraLiveTranscoding.default()
23+
var unpublishing = false
2324

2425
/**
2526
--- rtmpUrls Picker ---
@@ -43,18 +44,20 @@ class RTMPStreaming: BaseViewController {
4344
/// callback when remove streaming url button hit
4445
@IBAction func onRemoveStreamingURL(_ sender: Any) {
4546
guard let selectedURL = selectedrtmpUrl else { return }
46-
agoraKit.removePublishStreamUrl(selectedURL)
47+
agoraKit.stopRtmpStream(selectedURL)
48+
unpublishing = true
4749
rtmpURLs.remove(at: selectRtmpUrlsPicker.indexOfSelectedItem)
4850
selectRtmpUrlsPicker.picker.removeItem(at: selectRtmpUrlsPicker.indexOfSelectedItem)
4951
}
5052

5153
/// callback when remove all streaming url button hit
5254
@IBAction func onRemoveAllStreamingURL(_ sender: Any) {
5355
for url in rtmpURLs {
54-
agoraKit.removePublishStreamUrl(url)
56+
agoraKit.stopRtmpStream(url)
5557
}
5658
rtmpURLs = []
5759
selectRtmpUrlsPicker.picker.removeAllItems()
60+
unpublishing = true
5861
}
5962

6063
/**
@@ -345,9 +348,28 @@ extension RTMPStreaming: AgoraRtcEngineDelegate {
345348
if(state == .running) {
346349
self.showAlert(title: "Notice", message: "\(url) Publish Success")
347350
} else if(state == .failure) {
348-
self.showAlert(title: "Error", message: "\(url) Publish Failed: \(errorCode.rawValue)")
351+
agoraKit.stopRtmpStream(url)
352+
if errorCode == .streamingErrorCodeInternalServerError
353+
|| errorCode == .streamingErrorCodeStreamNotFound
354+
|| errorCode == .streamPublishErrorNetDown
355+
|| errorCode == .streamingErrorCodeConnectionTimeout {
356+
self.showAlert(title: "Error", message: "\(url) Publish Failed: \(errorCode.rawValue)")
357+
unpublishing = true
358+
}
349359
} else if(state == .idle) {
350360
self.showAlert(title: "Notice", message: "\(url) Publish Stopped")
361+
if !unpublishing {
362+
// start publishing to this URL
363+
if transcodingEnabled {
364+
agoraKit.startRtmpStreamWithTranscoding(url, transcoding: transcoding)
365+
}
366+
else {
367+
agoraKit.startRtmpStreamWithoutTranscoding(url)
368+
}
369+
}
370+
else {
371+
unpublishing = false
372+
}
351373
}
352374
}
353375

0 commit comments

Comments
 (0)