有一個章節的 VOD 播放 vod-playback-with-one-chapter

情境 scenario

此情境中,部分 VOD 內容會標示為章節。

除非另有指定,否則此情境中的網路呼叫與沒有廣告的 VOD 播放情境中的呼叫相同。網路呼叫會同時發生,但裝載不同。

觸發
心率方法
網路呼叫
附註
使用者點按​ 「播放」
trackSessionStart
Analytics 內容開始、心率內容開始
我們尚未通知 Measurement Library 有前段廣告,因此這些網路呼叫仍完全等同於單一 VoD。
章節開始。
trackEvent:ChapterStart
心率章節開始
章節播放的第一個時間格。
trackPlay
心率內容播放
當章節內容在主要內容之前播放,Heartbeats 會在章節開始時啟動。
章節播放。
章節心率
章節已完成。
trackEvent:trackChapterComplete
心率章節完成
此時已到達章節的結尾。
內容播放。
內容心率
此網路呼叫完全等同於沒有廣告的 VOD 播放情境。
內容已完成。
trackComplete
心率內容完成
此網路呼叫完全等同於沒有廣告的 VOD 播放情境。
工作階段已結束。
trackSessionEnd
SessionEnd 表示已達到檢視工作階段的結尾。即使使用者未持續觀看到媒體完成,仍必須呼叫此 API。

參數 parameters

當章節播放開始時,會傳送 Heartbeat Chapter Start 呼叫。如果章節的開頭不符合 10 秒的計時器,Heartbeat Chapter Start 呼叫會延遲幾秒,然後呼叫會進入下一個 10 秒的間隔。

發生此情況時,會以相同的間隔傳出 Content Heartbeat 呼叫。您可以透過檢查事件類型和資產類型來區分這兩者:

心率章節開始

參數
附註
s:event:type
"chapter_start"
s:asset:type
"main"
s:stream:chapter_*
章節資料特定的資料流資訊。
s:meta:*
具有特定上下文資料的章節。

程式碼範例、中間的章節 sample-code-chapter-in-the-middle

此情境中,部分 VOD 內容為章節。

Android

如要在 Android 中查看此情境,請設定下列程式碼:

// Set up mediaObject
MediaObject mediaInfo = MediaHeartbeat.createMediaObject(
  Configuration.MEDIA_NAME,
  Configuration.MEDIA_ID,
  Configuration.MEDIA_LENGTH,
  MediaHeartbeat.StreamType.VOD
);

HashMap<String, String> mediaMetadata = new HashMap<String, String>();
mediaMetadata.put(CUSTOM_KEY_1, CUSTOM_VAL_1);
mediaMetadata.put(CUSTOM_KEY_2, CUSTOM_VAL_2);

// 1. Call trackSessionStart() when the user clicks Play or if autoplay is used,
//    i.e., there is an intent to start playback.
_mediaHeartbeat.trackSessionStart(mediaInfo, mediaMetadata);

......
......

// 2. Call trackPlay() when the playback actually starts, i.e., first frame of the
//    ad media is rendered on the screen.
_mediaHeartbeat.trackPlay();

.......
.......

// Chapter
HashMap<String, String> chapterMetadata = new HashMap<String, String>();
chapterMetadata.put(CUSTOM_KEY_1, CUSTOM_VAL_1);
MediaObject chapterDataInfo =
MediaHeartbeat.createChapterObject(CHAPTER_NAME,
                                   CHAPTER_POSITION,
                                   CHAPTER_LENGTH,
                                   CHAPTER_START_TIME);

// 3. Track the MediaHeartbeat.Event.ChapterStart event when the chapter starts to play.
_mediaHeartbeat.trackEvent(MediaHeartbeat.Event.ChapterStart, chapterDataInfo, chapterMetadata);

.......
.......

// 4. Track the MediaHeartbeat.Event.ChapterComplete event when the chapter finishes playing.
_mediaHeartbeat.trackEvent(MediaHeartbeat.Event.ChapterComplete, null, null);

.......
.......

// 5. Call trackComplete() when the playback reaches the end, i.e., completes and finishes playing.
_mediaHeartbeat.trackComplete();

........
........

// 6. Call trackSessionEnd() when the playback session is over. This method must be called even
//    if the user does not watch the media to completion.
_mediaHeartbeat.trackSessionEnd();

........
........

iOS

如要在 iOS 中查看此情境,請設定下列程式碼:

when the user clicks Play
ADBMediaObject *mediaObject =
[ADBMediaHeartbeat createMediaObjectWithName:MEDIA_NAME
                   length:MEDIA_LENGTH
                   streamType:ADBMediaHeartbeatStreamTypeVOD];

NSMutableDictionary *mediaContextData = [[NSMutableDictionary alloc] init];
[mediaContextData setObject:CUSTOM_VAL_1 forKey:CUSTOM_KEY_1];
[mediaContextData setObject:CUSTOM_VAL_2 forKey:CUSTOM_KEY_2];

// 1. Call trackSessionStart when the user clicks Play or if autoplay is used,
//    i.e., when there is an intent to start playback.
[_mediaHeartbeat trackSessionStart:mediaObject data:mediaContextData];
.......
.......

// 2. Call trackPlay when the playback actually starts, i.e., when the
//    first frame of the main content is rendered on the screen.
[_mediaHeartbeat trackPlay];
.......
.......

// Chapter
NSMutableDictionary *chapterContextData = [[NSMutableDictionary alloc] init];
[chapterContextData setObject:CONTEXT_DATA_VALUE forKey:CONTEXT_DATA_KEY];

id chapterInfo =
[ADBMediaHeartbeat createChapterObjectWithName:CHAPTER_NAME
                   position:CHAPTER_POSITION
                   length:CHAPTER_LENGTH
                   startTime:CHAPTER_START_TIME];

// 3. Track the ADBMediaHeartbeatEventChapterStart event when the chapter
//    starts to play.
[_mediaHeartbeat trackEvent:ADBMediaHeartbeatEventChapterStart
               mediaObject:chapterInfo
               data:chapterContextData];
.......
.......

// 4. Track the ADBMediaHeartbeatEventChapterComplete event when the chapter
//    finishes playing.
[_mediaHeartbeat trackEvent:ADBMediaHeartbeatEventChapterComplete
               mediaObject:nil
               data:nil];
.......
.......
// 5. Call trackComplete when the playback reaches the end, i.e., when the
//    media completes and finishes playing.
[_mediaHeartbeat trackComplete];
.......
.......
// 6. Call trackSessionEnd when the playback session is over. This method must
//    be called even if the user does not watch the media to completion.
[_mediaHeartbeat trackSessionEnd];
.......
.......

JavaScript

若要在 JavaScript 中檢視此情境,請輸入下列文字:

// Set up mediaObject
var mediaInfo = MediaHeartbeat.createMediaObject(
 Configuration.MEDIA_NAME,
 Configuration.MEDIA_ID,
 Configuration.MEDIA_LENGTH,
 MediaHeartbeat.StreamType.VOD

);

var mediaMetadata = {
  CUSTOM_KEY_1 : CUSTOM_VAL_1,
  CUSTOM_KEY_2 : CUSTOM_VAL_2,
  CUSTOM_KEY_3 : CUSTOM_VAL_3
};

// 1. Call trackSessionStart when Play is clicked or if autoplay is used,
//    i.e., when there's an intent to start playback.
this._mediaHeartbeat.trackSessionStart(mediaInfo, mediaMetadata);

......
......

// Chapter
var chapterMetadata = {
  CUSTOM_KEY_1 : CUSTOM_VAL_1
};

var chapterDataInfo =
MediaHeartbeat.createChapterObject(CHAPTER_NAME,
                                   CHAPTER_POSITION,
                                   CHAPTER_LENGTH,
                                   CHAPTER_START_TIME);

// 2. Track the MediaHeartbeat.Event.ChapterStart event when the chapter
//    starts to play.
this._mediaHeartbeat.trackEvent(MediaHeartbeat.Event.ChapterStart,
                              chapterDataInfo,
                              chapterMetadata);

.......
.......

// 3. Call trackPlay() when the playback actually starts, i.e., when the first
//    frame of the main content is rendered on the screen.
this._mediaHeartbeat.trackPlay();

.......
.......

// 4. Track the MediaHeartbeat.Event.ChapterComplete event when the chapter
//    finishes playing.
this._mediaHeartbeat.trackEvent(MediaHeartbeat.Event.ChapterComplete);

.......
.......

// 5. Call trackComplete() when the playback reaches the end, i.e., when playback
//    completes and finishes playing.
this._mediaHeartbeat.trackComplete();

........
........

// 6. Call trackSessionEnd() when the playback session is over. This method must be
//    called even if the user does not watch the media to completion.
this._mediaHeartbeat.trackSessionEnd();

........
........

程式碼範例、開頭的章節 sample-code-chapter-at-the-beginning

此情境中,VOD 內容會播放,而在播放的開頭具有一個章節。

Android

如要在 Android 中查看此情境,請設定下列程式碼:

// Set up mediaObject
MediaObject mediaInfo = MediaHeartbeat.createMediaObject(
  Configuration.MEDIA_NAME,
  Configuration.MEDIA_ID,
  Configuration.MEDIA_LENGTH,
  MediaHeartbeat.StreamType.VOD
);

HashMap<String, String> mediaMetadata = new HashMap<String, String>();
mediaMetadata.put(CUSTOM_KEY_1, CUSTOM_VAL_1);
mediaMetadata.put(CUSTOM_KEY_2, CUSTOM_VAL_2);

// 1. Call trackSessionStart() when the user clicks Play or if autoplay is used,
//    i.e., there is an intent to start playback.
_mediaHeartbeat.trackSessionStart(mediaInfo, mediaMetadata);

......
......

// 2. Call trackPlay() when the playback actually starts, i.e., first frame of the
//    main content is rendered on the screen.
_mediaHeartbeat.trackPlay();

.......
.......

// Chapter
HashMap<String, String> chapterMetadata = new HashMap<String, String>();
chapterMetadata.put(CUSTOM_KEY_1, CUSTOM_VAL_1);
MediaObject chapterDataInfo =
MediaHeartbeat.createChapterObject(CHAPTER_NAME,
                                   CHAPTER_POSITION,
                                   CHAPTER_LENGTH,
                                   CHAPTER_START_TIME);

// 3. Track the MediaHeartbeat.Event.ChapterStart event when the chapter starts to play.
_mediaHeartbeat.trackEvent(MediaHeartbeat.Event.ChapterStart, chapterDataInfo, chapterMetadata);

.......
.......

// 4. Track the MediaHeartbeat.Event.ChapterComplete event when the chapter finishes playing.
_mediaHeartbeat.trackEvent(MediaHeartbeat.Event.ChapterComplete, null, null);

.......
.......

// 5. Call trackComplete() when the playback reaches the end, i.e., when the media completes
//    and finishes playing.
_mediaHeartbeat.trackComplete();

........
........

// 6. Call trackSessionEnd() when the playback session is over. This method must be called even
//    if the user does not watch the media to completion.
_mediaHeartbeat.trackSessionEnd();

........
........

iOS

如要在 iOS 中查看此情境,請設定下列程式碼:

when the user clicks Play
ADBMediaObject *mediaObject =
[ADBMediaHeartbeat createMediaObjectWithName:MEDIA_NAME
                   length:MEDIA_LENGTH
                   streamType:ADBMediaHeartbeatStreamTypeVOD];

NSMutableDictionary *mediaContextData = [[NSMutableDictionary alloc] init];
[mediaContextData setObject:CUSTOM_VAL_1 forKey:CUSTOM_KEY_1];
[mediaContextData setObject:CUSTOM_VAL_2 forKey:CUSTOM_KEY_2];

// 1. Call trackSessionStart when the user clicks Play or if autoplay is used,
//    i.e., there is an intent to start playback.
[_mediaHeartbeat trackSessionStart:mediaObject data:mediaContextData];
.......
.......

// Chapter
NSMutableDictionary *chapterContextData = [[NSMutableDictionary alloc] init];
[chapterContextData setObject:CONTEXT_DATA_VALUE forKey:CONTEXT_DATA_KEY];

id chapterInfo =
[ADBMediaHeartbeat createChapterObjectWithName:CHAPTER_NAME
                   position:CHAPTER_POSITION
                   length:CHAPTER_LENGTH
                   startTime:CHAPTER_START_TIME];

// 2. Call ADBMediaHeartbeatEventChapterStart when the chapter starts.
[_mediaHeartbeat trackEvent:ADBMediaHeartbeatEventChapterStart
               mediaObject:chapterInfo
               data:chapterContextData];
.......
.......

// 3. Call trackPlay when the playback actually starts, i.e., when the
//    first frame of the main content is rendered on the screen.
[_mediaHeartbeat trackPlay];
.......
.......

// 4. Call ADBMediaHeartbeatEventChapterComplete when the chapter starts.
[_mediaHeartbeat trackEvent:ADBMediaHeartbeatEventChapterComplete
               mediaObject:nil
               data:nil];
.......
.......

// 5. Call trackComplete when the playback reaches the end, i.e., when the
//    media completes and finishes playing.
[_mediaHeartbeat trackComplete];
.......
.......

// 6. Call trackSessionEnd when the playback session is over. This method
//    must be called even if the user does not watch the media to completion.
[_mediaHeartbeat trackSessionEnd];
.......
.......

JavaScript

若要在 JavaScript 中檢視此情境,請輸入下列文字:

// Set up mediaObject
var mediaInfo = MediaHeartbeat.createMediaObject(
 Configuration.MEDIA_NAME,
 Configuration.MEDIA_ID,
 Configuration.MEDIA_LENGTH,
 MediaHeartbeat.StreamType.VOD

);

var mediaMetadata = {
  CUSTOM_KEY_1 : CUSTOM_VAL_1,
  CUSTOM_KEY_2 : CUSTOM_VAL_2,
  CUSTOM_KEY_3 : CUSTOM_VAL_3
};

// 1. Call trackSessionStart() when Play is clicked or if autoplay is used,
//    i.e., when there's an intent to start playback.
this._mediaHeartbeat.trackSessionStart(mediaInfo, mediaMetadata);

......
......

// Chapter
var chapterMetadata = {
  CUSTOM_KEY_1 : CUSTOM_VAL_1
};

var chapterDataInfo =
MediaHeartbeat.createChapterObject(CHAPTER_NAME,
                                   CHAPTER_POSITION,
                                   CHAPTER_LENGTH,
                                   CHAPTER_START_TIME);

// 2. Track the MediaHeartbeat.Event.ChapterStart event when the chapter starts to play.
this._mediaHeartbeat.trackEvent(MediaHeartbeat.Event.ChapterStart,
                              chapterDataInfo,
                              chapterMetadata);

.......
.......

// 3. Call trackPlay() when the playback actually starts, i.e., when the first
//    frame of the main content is rendered on the screen.
this._mediaHeartbeat.trackPlay();

.......
.......

// 4. Track the MediaHeartbeat.Event.ChapterComplete event when the chapter
//    finishes playing.
this._mediaHeartbeat.trackEvent(MediaHeartbeat.Event.ChapterComplete);

.......
.......

// 5. Call trackComplete() when the playback reaches the end, i.e., when playback
//    completes and finishes playing.
this._mediaHeartbeat.trackComplete();

........
........

// 6. Call trackSessionEnd() when the playback session is over. This method must be
//    called even if the user does not watch the media to completion.
this._mediaHeartbeat.trackSessionEnd();

........
........
recommendation-more-help
c8eee520-cef5-4f8c-a38a-d4952cfae4eb