ライブストリーミングを停止
現在の RTSP または JPEG デバイスライブストリーミングを停止し、ホストアプリが管理するプレイヤー、中継、画像、UI の各リソースを解放します。
前提条件
- 対象デバイスが
LiveStreamingAPIに準拠していること。 - 現在のセッション用に作成した表示リソースへの参照を保持していること。
- 画面終了と明示的な停止操作で同じクリーンアップ処理を共有できるよう、停止処理を冪等にしていること。
API Reference
フレームワーク
AIBuds.xcframework
インポート
- Swift
- Objective-C
import AIBuds
import AIBudsLiveStream#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
#import <AIBudsLiveStream/AIBudsLiveStream-Swift.h>インスタンスメソッド
- Swift
- Objective-C
/// Stop live streaming
func stopLiveStreaming()/// Stop live streaming
- (void)stopLiveStreaming;stopLiveStreaming を参照してください。
パラメーター
このメソッドにパラメーターはありません。
戻り値
このメソッドは値を返さず、完了ハンドラーも受け取りません。セッション開始時に指定した sessionFinishHandler から最終結果を確認します。
使用例
Demo は任意の RTMP 中継を停止してから RTSP 再生を停止し、その後デバイスセッションと UI の状態を消去します。デバイスコマンドとホスト側リソースは別々のライフサイクルです。
- 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() には完了ハンドラーがないため、ローカルクリーンアップを安全に繰り返せるようにし、元のセッションの終了コールバックで isUserInitiatedStop と中断を区別します。セッションが予期せず終了した場合は、コールバックのエラーをログまたは UI に表示します。
ベストプラクティス
- 管理画面を離れるとき、または機能を終了するときにライブストリーミングを停止します。
- デバイスセッションとともに、RTMP 中継、プレイヤー、保持中の RTSP アドレスを解放します。
- 公開メソッドには存在しない停止完了を待たないでください。
- 終了コールバックはローカルクリーンアップ後に呼ばれる場合があるため、処理を冪等にします。
注意事項
- 同じ停止メソッドで RTSP または JPEG のデバイスセッションを終了します。
LiveStreamingPlayerだけを停止してもデバイスセッションは停止しません。- デバイスセッションだけを停止しても、ホストが管理する再生/中継オブジェクトは自動解放されません。