處理線性 DAI 串流中的定時中繼資料
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
互動式媒體廣告 (IMA) 動態廣告插播 SDK (DAI) 必須使用
內嵌於串流媒體區段的中繼資料資訊 (頻內中繼資料)
或透過串流資訊清單檔案 (資訊清單中繼資料) 追蹤檢視者
位置和用戶端廣告事件可從 DAI 串流取得中繼資料
根據要播放的串流類型
放送不同格式的廣告IMA DAI
SDK 會透過單一 API 處理所有中繼資料格式。
您的應用程式負責擷取中繼資料,並轉送至 IMA DAI SDK。SDK 提供了
StreamManager.onMessage()
敬上
方法來傳送這項資訊。這個方法會透過
roVideo 通訊埠提供的 msg
物件。接著,這些物件會經由
IMA DAI SDK 中設定廣告事件的時間。這個程序只需要
引數:
msg
:roVideo 通訊埠提供的訊息類型物件。
以下範例說明如何處理來自 roVideo 通訊埠的中繼資料
透過 StreamManager.onMessage()
將其傳遞至 IMA DAI SDK。
Sub runLoop()
' Forward all timed metadata events to IMA.
m.top.video.timedMetaDataSelectionKeys = ["*"]
' Cycle through all the fields and set listeners.
' IMPORTANT: Failure to listen to the position and timedmetadata fields could
' result in ad impressions not being reported.
m.port = CreateObject("roMessagePort")
fields = m.top.video.getFields()
for each field in fields
m.top.video.observeField(field, m.port)
end for
while True
msg = wait(1000, m.port)
if m.top.video = invalid
print "exiting"
exit while
end if
m.streamManager.onMessage(msg)
currentTime = m.top.video.position
If currentTime > 3 And not m.top.adPlaying
m.top.video.enableTrickPlay = true
End If
end while
End Sub
進一步瞭解如何整合迴圈處理串流中繼資料
請參閱
IMA Roku 入門指南。
「事件監聽器和串流開始」區段
的指南包含中繼資料處理迴圈
HTTP 即時串流 CMAF 串流
採用通用媒體應用程式架構 (CMAF) 傳遞的線性 DAI HLS 串流
透過頻內 eMSGv1 方塊 (網址:ID3 到
CMAF 標準。這些電子音樂盒
每個 ID3 eMSG 都嵌入
相對於串流上次中斷度的 PTS。
如果是 IMA Roku,所有 HLS CMAF 串流都會使用 eMSGv0 格式傳送頻內 ID3 資料。
IMA 結合了 eMSGv0 格式提供的資訊與資訊
從影片物件中嵌入
如要啟用正確剖析 HTTP 即時串流 CMAF 串流 ID3 事件,您必須將
透過
StreamRequest.videoObject
。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[null,null,["上次更新時間:2025-08-21 (世界標準時間)。"],[[["\u003cp\u003eThe IMA DAI SDK uses metadata embedded within media segments or streaming manifests to track viewer positions and ad events, simplifying ad insertion in live and on-demand content.\u003c/p\u003e\n"],["\u003cp\u003eYour app needs to capture metadata from the roVideo port and forward it to the IMA DAI SDK using the \u003ccode\u003eStreamManager.onMessage()\u003c/code\u003e method for proper ad tracking.\u003c/p\u003e\n"],["\u003cp\u003eHLS CMAF streams utilize in-band eMSGv1 boxes following the ID3 through CMAF standard to pass timed metadata for ad cue points.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure accurate parsing of HLS CMAF stream ID3 events, include the video object in the stream request using \u003ccode\u003eStreamRequest.videoObject\u003c/code\u003e.\u003c/p\u003e\n"]]],["The Interactive Media Ads (IMA) Dynamic Ad Insertion SDK uses in-band or in-manifest metadata to track viewer positions and ad events. Apps capture this metadata and use the `StreamManager.onMessage()` method to forward it to the SDK. This method processes `msg` objects from the roVideo port to time ad events. The example shows a loop that observes video fields, forwards timed metadata to IMA via `onMessage()`, and monitors the video's current position. HLS CMAF streams pass timed metadata via in-band eMSGv1 boxes.\n"],null,["# Handle timed metadata in linear DAI streams\n\nThe Interactive Media Ads (IMA) Dynamic Ad Insertion SDK (DAI) relies on\nmetadata information embedded in the stream's media segments (in-band metadata),\nor in the streaming manifest file (in-manifest metadata) to track viewers'\npositions and client-side ad events. Metadata is available from the DAI stream\nin different formats, depending on the type of stream being played. The IMA DAI\nSDK handles all metadata formats through a single API.\n\nYour app is responsible for capturing metadata and forwarding it to the IMA DAI SDK. The SDK offers the\n[`StreamManager.onMessage()`](/ad-manager/dynamic-ad-insertion/sdk/roku/apis#ima.StreamManager.onMessage)\nmethod to pass this information. This method forwards metadata in the form of a\n`msg` object provided by the roVideo port. These objects are then processed by\nthe IMA DAI SDK to establish the timing for ad events. It takes a single\nargument:\n\n- `msg`: a msg type object provided by the roVideo port.\n\nMetadata sample code\n--------------------\n\nHere's an example of how to handle the metadata from the roVideo port and\npass it to the IMA DAI SDK through `StreamManager.onMessage()`. \n\n Sub runLoop()\n ' Forward all timed metadata events to IMA.\n m.top.video.timedMetaDataSelectionKeys = [\"*\"]\n\n ' Cycle through all the fields and set listeners.\n ' IMPORTANT: Failure to listen to the position and timedmetadata fields could\n ' result in ad impressions not being reported.\n m.port = CreateObject(\"roMessagePort\")\n fields = m.top.video.getFields()\n for each field in fields\n m.top.video.observeField(field, m.port)\n end for\n\n while True\n msg = wait(1000, m.port)\n if m.top.video = invalid\n print \"exiting\"\n exit while\n end if\n\n m.streamManager.onMessage(msg)\n currentTime = m.top.video.position\n If currentTime \u003e 3 And not m.top.adPlaying\n m.top.video.enableTrickPlay = true\n End If\n end while\n End Sub\n\nFor more information on how to incorporate the loop handling stream metadata\ninto your app, see the\n[IMA Roku getting started guide](/ad-manager/dynamic-ad-insertion/sdk/roku). The\n[event listener and stream start section](/ad-manager/dynamic-ad-insertion/sdk/roku#add-event-listeners-and-start-the-stream)\nof the guide contains the metadata handling loop.\n\nHLS CMAF streams\n----------------\n\nLinear DAI HLS streams using the Common Media Application Framework (CMAF) pass\ntimed metadata through in-band eMSGv1 boxes following the [ID3 through\nCMAF](//aomediacodec.github.io/id3-emsg/) standard. These eMSG boxes are\nembedded at the beginning of each media segment, with each ID3 eMSG containing\na PTS relative to the last discontinuity in the stream.\n\nFor IMA Roku, all HLS CMAF streams send in-band ID3 data using the eMSGv0 format.\nIMA combines information provided by the eMSGv0 format with information\nfrom the video object.\n\nTo enable proper parsing of HLS CMAF stream ID3 events, you must send your\nvideo object in the stream request using\n[`StreamRequest.videoObject`](/ad-manager/dynamic-ad-insertion/sdk/roku/apis#ima.StreamRequest.videoObject)."]]