跟蹤播放器中的AVE警告

使用NotificationEvent,可以跟蹤從Adobe視頻引擎(AVE)傳遞的警告。

您的播放器應用可以跟蹤AVE生成的播放警告和錯誤,例如故障轉移或網路關閉事件,這些事件不會停止播放,並且不一定需要應用執行任何操作。 雖然TVSDK處理了某些AVE錯誤, NotificationEvent 作為AVE警告的通用傳遞機制,可傳遞給應用層。 在收到AVE警告後,您可能會選擇採取一些措施,如主動停止播放、激活應急計畫、記錄消息等。

使用以下API元素跟蹤播放器中的AVE警告:

通知代碼

public final class NotificationCode {
    /**
     * Warning message for playback status.
     */
    public static const GENERAL_WARNING:int = 101100;
}

通知事件

/**
 * Event dispatched by MediaPlayer when a notification is available
 * for the current media stream being played.
 */
public class NotificationEvent extends Event {
    /**
     * Event dispatched when a new warning has been received for the current item.
     *
     * The newly created Notification object can be accessed through
     * the notification property of this event.
     */
    public static const WARNING_AVAILABLE:String = "warningAvailable";
    /**
     * Helper method for creating NotificationEvent events.
     * Throws an ArgumentError if the specified ad break is null.
     * @param notification Associated notification object.
     *
     * @return a valid notification event instance.
     */
    public static function create(
           type:String, notification:Notification):NotificationEvent;
     /**
     * Default constructor
     * Throws an ArgumentError if the specified ad break is null.
     * @param type           Event type.
     * @param bubbles        Whether the event can bubble up the display list hierarchy.
     * @param cancelable     Whether the behavior associated with the event can be prevented.
     * @param notification   Associated notification object.
     */
    public function NotificationEvent(type:String,
                                      bubbles:Boolean=false,
                                      cancelable:Boolean=false,
                                      notification:Notification= null);
     /**
     * The notification associated with this event.
     */
    public function get notification():Notification;
    /**
     * @inheritDoc
     */
    public override function clone():Event;
}

將事件偵聽器添加到播放器以捕獲AVE警告。

例如:

var _player:DefaultMediaPlayer = new DefaultMediaPlayer(context);
_player.addEventListener(NotificationEvent.WARNING_AVAILABLE, onWarningAvailable);

private function onWarningAvailable(event:NotificationEvent):void {
    var metadata:Metadata = event.notification.metadata;
    if (metadata != null) {
        for each (var key:String in metadata.keySet()) {
            var value:String = metadata.getValue(key);
            if (!StringUtils.isEmpty(key) && !StringUtils.isEmpty(value)) {
                _logger.warn("#onWarningAvailable metadata [{0}:{1}]", key, value);
            }
        }
    }
}

以下是使用 NotificationEvent:

[WARN ] [psdkdemo::PSDKDemo] #onWarningAvailable metadata [resourceType:HLS]
[WARN ] [psdkdemo::PSDKDemo] #onWarningAvailable metadata [resourceId:0]
[WARN ] [psdkdemo::PSDKDemo] #onWarningAvailable metadata [runtimeCode:66]
[WARN ] [psdkdemo::PSDKDemo] #onWarningAvailable metadata [runtimeCodeMessage:SEGMENT_SKIPPED_ON_FAILURE]
[WARN ] [psdkdemo::PSDKDemo] #onWarningAvailable metadata [eventType:Warning]

<pre>
  [WARN ] [psdkdemo::PSDKDemo] #onWarningAvailable metadata [description:url::=
   https://xyz.corp.adobe.com/pmp/assets/abc/failover/tc.1.04/content/backup-01/
   low-res/main-stream4-4x3-info6.ts,periodIndex::=0,
   sizeBytes::=0,downloadTime(ms)::=0,mediaDuration(ms)::=0]
</pre>

本頁內容