Show Menu
主题×

恢复不活动的会话

长时间暂停

Media SDK 会自动跟踪媒体播放处于下列某个不活动状态的时长:
  • 暂停
  • 搜寻
  • 停滞
  • 缓冲
如果媒体跟踪会话保持不活动状态超过 30 分钟,则该会话将被自动关闭。如果用户恢复之前不活动的视频跟踪会话 (
trackPlay
),媒体心率会使用先前使用的视频信息和元数据自动创建新的视频会话,并发送恢复心率事件。有关更多信息,请参阅 音频和视频参数

手动恢复之前关闭的会话

Media SDK 仅在应用程序未关闭的情况下才会自动恢复会话。如果应用程序存储了用户数据,并且能够恢复之前关闭的媒体,则可以手动触发恢复事件。启动视频跟踪会话时,请设置可选的“视频已恢复”属性。

Android

// Set MediaHeartbeat.MediaObjectKey.mediaResumed to true public void onmediaLoad(Observable observable, Object data) { // Replace <MEDIA_NAME> with the media name. // Replace <MEDIA_ID> with a media unique identifier. // Replace <MEDIA_LENGTH> with the media length. MediaObject mediaInfo = MediaHeartbeat.createMediaObject( <MEDIA_NAME>, <MEDIA_ID>, <MEDIA_LENGTH>, MediaHeartbeat.StreamType.VOD ); // Set to true if this is a resume playback scenario mediaInfo.setValue(MediaHeartbeat.MediaObjectKey.mediaResumed, true); _heartbeat.trackSessionStart(mediaInfo, mediaMetadata); }

iOS

- (void)onMainmediaLoaded:(NSNotification *)notification { //Replace <MEDIA_NAME> with the media name. //Replace <MEDIA_ID> with a media unique identifier. //Replace <MEDIA_LENGTH> with the media length. ADBMediaObject *mediaObject = [ADBMediaHeartbeat createMediaObjectWithName:<MEDIA_NAME> mediaId:<MEDIA_ID> length:<MEDIA_LENGTH> streamType:ADBMediaHeartbeatStreamTypeVOD]; //Set to YES if this user is resuming a previously closed media session [mediaObject setValue:@(YES) forKey:ADBMediaObjectKeymediaResumed]; [_mediaHeartbeat trackSessionStart:mediaObject data:mediaMetadata]; }

JavaScript

_onmediaLoad = function () { // Replace <MEDIA_NAME> with the media name. // Replace <MEDIA_ID> with a media unique identifier. // Replace <MEDIA_LENGTH> with the media length. var mediaObject = MediaHeartbeat.createMediaObject(<MEDIA_NAME>, <MEDIA_ID, <MEDIA_LENGTH>, MediaHeartbeat.StreamType.VOD); // Set to true if this user is resuming a previously closed media session mediaObject.setValue(MediaObjectKey.mediaResumed, true); this._mediaHeartbeat.trackSessionStart(mediaObject, contextData); };