लाइव स्ट्रीमिंग रोकें
मौजूदा RTSP या JPEG device live-stream session रोकें और host app के player, relay, image तथा UI resources release करें।
आवश्यकताएँ
- Target डिवाइस
LiveStreamingAPIके अनुरूप है। - मौजूदा session के लिए बने presentation resources के references रखें।
- Stop handling को idempotent रखें ताकि view dismissal और explicit stop action एक cleanup path साझा कर सकें।
API संदर्भ
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds
import AIBudsLiveStream#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
#import <AIBudsLiveStream/AIBudsLiveStream-Swift.h>Instance विधि
- Swift
- Objective-C
/// Stop live streaming
func stopLiveStreaming()/// Stop live streaming
- (void)stopLiveStreaming;stopLiveStreaming देखें।
पैरामीटर
इस method के कोई parameters नहीं हैं।
Return मान
यह method value return या completion handler स्वीकार नहीं करता। Final context के लिए session शुरू करते समय दिया sessionFinishHandler देखें।
उपयोग के उदाहरण
Demo RTSP playback रोकने से पहले optional RTMP relay रोकता है, फिर device-session और UI state साफ़ करता है। Device command और host resources के lifecycle अलग हैं।
- Swift
- Objective-C
func stopCurrentLiveStream() {
// Stop optional host-side relay and playback resources.
liveStreamer?.stopStreaming()
liveStreamer = nil
mediaPlayer?.stop()
// Stop the RTSP or JPEG session on the connected device.
(device as? LiveStreamingAPI)?.stopLiveStreaming()
currentRTSPAddress = nil
imageView.image = nil
setStreamingActive(false)
}- (void)stopCurrentLiveStream {
// Stop optional host-side relay and playback resources.
[self.liveStreamer stopStreaming];
self.liveStreamer = nil;
[self.mediaPlayer stop];
// Stop the RTSP or JPEG session on the connected device.
id<AIBudsLiveStreamingAPI> streamingDevice = (id<AIBudsLiveStreamingAPI>)self.device;
if ([streamingDevice conformsToProtocol:@protocol(AIBudsLiveStreamingAPI)]) {
[streamingDevice stopLiveStreaming];
}
self.currentRtspAddress = nil;
self.imageView.image = nil;
[self setStreamingActive:NO];
}त्रुटि प्रबंधन
stopLiveStreaming() में completion handler नहीं है, इसलिए local cleanup को दोहराना safe रखें और isUserInitiatedStop को interruption से अलग करने के लिए original session का finish callback उपयोग करें। Session अचानक समाप्त हो तो callback error log या दिखाएँ।
श्रेष्ठ अभ्यास
- संबंधित screen छोड़ते या feature समाप्त करते समय live streaming रोकें।
- RTMP relay, player और रखा RTSP address device session के साथ release करें।
- Public method जो stop completion नहीं देता, उसकी प्रतीक्षा न करें।
- Finish-callback handling idempotent रखें क्योंकि यह local cleanup के बाद चल सकता है।
नोट्स
- वही stop method RTSP या JPEG device session समाप्त करता है।
- केवल
LiveStreamingPlayerरोकने से device session नहीं रुकता। - केवल device session रोकने से host-owned playback या relay objects अपने-आप release नहीं होते।