Roku – SceneGraph 中的跟踪 tracking-in-scenegraph-roku
简介 introduction
您可以使用 Roku SceneGraph XML 编程框架来开发应用程序。此框架具有两个关键概念:
- 应用程序屏幕的 SceneGraph 渲染
- SceneGraph 屏幕的 XML 配置
Adobe Mobile SDK for Roku 使用 BrightScript 编写。SDK 使用的许多组件不适用于在 SceneGraph 上运行的应用程序(例如线程)。因此,计划使用 SceneGraph 框架的 Roku 应用程序开发人员无法调用 Adobe Mobile SDK API(后者类似于旧版 BrightScript 应用程序中提供的 API)。
体系结构 architecture
为了向 AdobeMobile SDK 添加 SceneGraph 支持,Adobe 已添加了一个新的 API,通过此 API,可在 AdobeMobile SDK 和 adbmobileTask
之间创建一个连接器桥。后者是用于 SDK API 执行的 SceneGraph 节点。(在本文档的其他部分中对 adbmobileTask
的用法进行了详细解释。)
连接器桥旨在执行以下操作:
- 桥会返回 AdobeMobile SDK 的与 SceneGraph 兼容的实例。与 SceneGraph 兼容的 SDK 具有旧版 SDK 公开的所有 API。
- 在 SceneGraph 中使用 Adobe Mobile SDK API 的方式与使用旧版 API 的方式非常相似。
- 桥还公开了一种机制来侦听返回某些数据的 API 的回调。
组件 components
SceneGraph 应用程序:
- 通过 SceneGraph 连接器桥 API 使用
AdobeMobileLibrary
API。 - 在
adbmobileTask
中为预期的输出数据变量注册响应回调。
AdobeMobileLibrary:
- 公开一组公共 API(旧版),包括连接器桥 API。
- 返回包含所有旧版公共 API 的 SceneGraph 连接器实例。
- 与用于执行 API 的
adbmobileTask
SceneGraph 节点通信。
adbmobileTask 节点:
- 可在后台线程上执行
AdobeMobileLibrary
API 的 SceneGraph 任务节点。 - 用作将数据返回到应用程序场景的委托。
公共 SceneGraph API public-scenegraph-apis
ADBMobileConnector
sceneGraphConstants
SceneGraphConstants
的对象。有关详细信息,请参阅上表。setDebugLogging
getDebugLogging
setPrivacyStatus
getPrivacyStatus
trackState
trackAction
trackingIdentifier
userIdentifier
setUserIdentifier
getAllIdentifiers
visitorSyncIdentifiers
visitorMarketingCloudID
audienceSubmitSignal
audienceVisitorProfile
audienceDpid
audienceDpuuid
audienceSetDpidAndDpuuid
mediaTrackLoad
mediaTrackUnload
mediaTrackPlay
mediaTrackComplete
mediaTrackError
mediaUpdatePlayhead
mediaUpdateQoS
SceneGraphConstants
API_RESPONSE
adbmobileTask
节点的 adbmobileApiResponse
字段中检索响应对象DEBUG_LOGGING
getDebugLogging
的 apiName
PRIVACY_STATUS
getPrivacyStatus
的 apiName
TRACKING_IDENTIFIER
trackingIdentifier
的 apiName
USER_IDENTIFIER
userIdentifier
的 apiName
VISITOR_MARKETING_CLOUD_ID
visitorMarketingCloudID
的 apiName
AUDIENCE_VISITOR_PROFILE
audienceVisitorProfile
的 apiName
AUDIENCE_DPID
audienceDpid
的 apiName
AUDIENCE_DPUUID
audienceDpuuid
的 apiName
adbmobileTask 节点
只读。在 AdobeMobileSDK 中执行的所有 API 都将返回此字段中的响应。注册侦听此字段更新的回调,以接收响应对象。以下是响应对象的格式:
response = {
"apiName" : <SceneGraphConstants.
API_NAME>
"returnValue : <API_RESPONSE>
}
将为 AdobeMobileSDK 中的任何 API 调用发送此响应对象的实例,根据 API 引用指南,该 API 调用应会返回一个值。例如,visitorMarketingCloudID() 的 API 调用将返回以下响应对象:
response = {
"apiName" : m.
adbmobileConstants.
VISITOR_MARKETING_CLOUD_ID
"returnValue : "07050x25671x33760x72644x14"
}
或者,响应数据也可能无效:
response = {
"apiName" : m.
adbmobileConstants.
VISITOR_MARKETING_CLOUD_ID
"returnValue : invalid
}
adbmobile.brs
getADBMobileConnectorInstance
API 签名:ADBMobile().getADBMobileConnectorInstance()
输入:adbmobileTask
返回类型:ADBMobileConnector
sgConstants
API 签名:ADBMobile().sgConstants()
输入:无
返回类型:SceneGraphConstants
ADBMobileConnector
API 引用。ADBMobile 常量
version
PRIVACY_STATUS_OPT_IN
PRIVACY_STATUS_OPT_OUT
旧版 AdobeMobileLibrary 中全局定义的实用程序 MediaHeartbeat
API 可在 SceneGraph 环境中“照常”**进行访问,因为它们未使用任何无法在 SceneGraph 节点中使用的 Brightscript 组件。有关这些方法的更多信息,请参阅下表:
适用于 MediaHeartbeat 的全局方法
adb_media_init_mediainfo
Function adb_media_init_mediainfo(name As String, id As String, length As Double, streamType As String) As Object
adb_media_init_adinfo
Function adb_media_init_adinfo(name As String, id As String, position As Double, length As Double) As Object
adb_media_init_chapterinfo
Function adb_media_init_adbreakinfo(name As String, startTime as Double, position as Double) As Object
adb_media_init_adbreakinfo
Function adb_media_init_chapterinfo(name As String, position As Double, length As Double, startTime As Double) As Object
adb_media_init_qosinfo
Function adb_media_init_qosinfo(bitrate As Double, startupTime as Double, fps as Double, droppedFrames as Double) As Object
实施 implementation
-
下载 Roku 库 - 下载最新版本的 Roku 库。
-
设置开发环境
-
将
adbmobile.brs
(AdobeMobileLibrary) 复制到pkg:/source/
目录中。 -
要支持 Scene Graph,请将
adbmobileTask.brs
和adbMobileTask.xml
复制到pkg:/components/
目录中。
-
-
初始化
-
将
adbmobile.brs
导入到场景中。code language-none <script type="text/brightscript" uri="pkg:/source/adbmobile.brs" />
-
在场景中创建一个
adbmobileTask
节点的实例。code language-none m.adbmobileTask = createObject("roSGNode", "adbmobileTask")
-
使用
adbmobile
实例获取 SceneGraph 的adbmobileTask
连接器实例。code language-none m.adbmobile = ADBMobile().getADBMobileConnectorInstance(m.adbmobileTask)
-
获取
adbmobile
SG 常量。code language-none m.adbmobileConstants = m.adbmobile.sceneGraphConstants()
-
注册一个回调以接收所有
AdbMobile
API 调用的响应对象。code language-none m.adbmobileTask.ObserveField(m.adbmobileConstants.API_RESPONSE, "onAdbmobileApiResponse") ' Sample implementation of the callback ' Listen for all the constants for which API calls are made on the SDK function onAdbmobileApiResponse() as void responseObject = m.adbmobileTask[m.adbmobileConstants.API_RESPONSE] if responseObject <> invalid methodName = responseObject.apiName retVal = responseObject.returnValue if methodName = m.adbmobileConstants.DEBUG_LOGGING if retVal print "API Response: DEBUG LOGGING: " + "True" else print "API Response: DEBUG LOGGING: " + "False" endif else if methodName = m.adbmobileConstants.PRIVACY_STATUS print "API Response: PRIVACY STATUS: " + retVal else if methodName = m.adbmobileConstants.TRACKING_IDENTIFIER if retVal <> invalid print "API Response: TRACKING IDENTIFIER: " + retVal else print "API Response: TRACKING IDENTIFIER: " + "invalid" endif else if methodName = m.adbmobileConstants.USER_IDENTIFIER if retVal <> invalid print "API Response: USER IDENTIFIER: " + retVal else print "API Response: USER IDENTIFIER: " + "invalid" endif else if methodName = m.adbmobileConstants.VISITOR_MARKETING_CLOUD_ID if retVal <> invalid print "API Response: MCID: " + retVal else print "API Response: MCID: " + "invalid" endif else if methodName = m.adbmobileConstants.AUDIENCE_DPID if retVal <> invalid print "API Response: AUDIENCE DPID: " + retVal else print "API Response: AUDIENCE DPID: " + "invalid" endif else if methodName = m.adbmobileConstants.AUDIENCE_DPUUID if retVal <> invalid print "API Response: AUDIENCE DPUUID: " + retVal else print "API Response: AUDIENCE DPUUID: " + "invalid" endif else if methodName = m.adbmobileConstants.AUDIENCE_VISITOR_PROFILE if retVal <> invalid print "API Response: AUDIENCE VISITOR PROFILE: Valid Object" else print "API Response: AUDIENCE VISITOR PROFILE: " + "invalid" endif endif endif end function
-
实施示例 sample-implementation
旧版 SDK 中的 API 调用示例
'get an instance of SDK
m.adbmobile = ADBMobile()
'execute setter APIs
m.adbmobile.setDebugLogging(true)
'execute getter APIs
debugLogging = m.adbmobile.getDebugLogging()
SG SDK 中的 API 调用示例
'create adbmobileTask instance
m.adbmobileTask = createObject("roSGNode", "adbmobileTask")
'get an instance of SDK using task instance
m.adbmobile =
ADBMobile().getADBMobileConnectorInstace(m.adbmobileTask)
m.adbmobileConstants = m.adbmobile.sceneGraphConstants()
'execute setter APIs
m.adbmobile.setDebugLogging(true)
'execute getter APIs
m.adbmobileTask.ObserverField(m.adbConstants.API_RESPONSE,
"onAdbmobileApiResponse")
m.adbmobile.getDebugLogging()
'listen for return data in registered callbacks
function onAdbmobileApiResponse() as void
responseObject = m.adbmobileTask[m.adbmobileConstants.API_RESPONSE]
if responseObject <> invalid
methodName = responseObject.apiName
retVal = responseObject.returnValue
if methodName = m.adbmobileConstants.DEBUG_LOGGING
if retVal
print "API Response: DEBUG LOGGING: " + "True"
else
print "API Response: DEBUG LOGGING: " + "False"
endif
endif
end function