概覽
通過服務器端廣告插入(SSAI)交付實時流時,您可以使用“實時”模塊請求插播廣告間隔。有關詳細信息,請參見將Live SSAI與本機SDK結合使用文件。
您可能還想在直播開始之前添加前置廣告。這是觀眾參與並願意觀看簡短廣告的時候。借助此功能,您可以插入客戶端IMA前置廣告。
需求
此功能需要滿足以下要求:
布萊特灣原生 SDK 版本
- 適用於Android 6.10.0或更高版本的Native SDK
- 適用於iOS / tvOS 6.7.7或更高版本的本機SDK
平台
- 帳戶已啟用動態投放
使用Live SSAI實施IMA前置廣告
要使用實時SSAI流播放IMA前置廣告,請按照以下步驟操作:
-
創建一個啟用了服務器端廣告插入(SSAI)的實時事件。如需詳細資訊,請參閱下列內容:
-
使用IMA插件來啟用客戶端前置廣告。有關詳細信息,請參見使用本機SDK實施客戶端廣告文件。
- 開始流式傳輸。
安卓實作
對於此功能,您將同時使用 IMA 和 SSAI 外掛程式:
代碼樣本
若要實作此功能,請檢閱下列範例:
- 使用Android SDK直播LiveSampleApp)
- 帶有Android SDK的SSAI( BasicSsaiSampleApp)
- 帶有Android SDK的IMA廣告( AdRulesIMASampleApp)
範例
以下是結合了實時,SSAI和IMA預卷廣告的代碼示例:
/**
* We start by adding some variables that are focused on the CSAI integration:
* Also make the EventEmitter a global variable, it will be needed in the setupGoogleIMA method below
*/
private EventEmitter eventEmitter;
private GoogleIMAComponent googleIMAComponent;
private String adRulesURL = "YOUR_AD_RULES_URL";
private final String AD_CONFIG_ID_QUERY_PARAM_KEY = "ad_config_id";
// Note that for live SSAI streams, the adConfigId will start with the string "live."
// Ads will be injected into a live SSAI stream using the cue point API
private final String AD_CONFIG_ID_QUERY_PARAM_VALUE = "YOUR_AD_CONFIG_ID";
private SSAIComponent plugin;
/**
* The BasicSSAISampleApp's onCreateMethod, with the setupGoogleIMA method from the AdRulesImaSampleApp added
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.ssai_activity_main);
brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
super.onCreate(savedInstanceState);
eventEmitter = brightcoveVideoView.getEventEmitter();
// Here we use the same setupGoogleIMA method as found in the AdRulesImaSampleApp:
setupGoogleIMA();
final EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter();
Catalog catalog = new Catalog(eventEmitter, YOUR_ACCOUNT_ID, YOUR_POLICY_KEY);
// Setup the error event handler for the SSAI plugin.
registerErrorEventHandler();
plugin = new SSAIComponent(this, brightcoveVideoView);
View view = findViewById(R.id.ad_frame);
if (view instanceof ViewGroup) {
// Set the companion ad container,
plugin.addCompanionContainer((ViewGroup) view);
}
// Set the HttpRequestConfig with the Ad Config Id configured in
// your https://studio.brightcove.com account.
HttpRequestConfig httpRequestConfig = new HttpRequestConfig.Builder()
.addQueryParameter(AD_CONFIG_ID_QUERY_PARAM_KEY, AD_CONFIG_ID_QUERY_PARAM_VALUE)
.build();
catalog.findVideoByID("YOUR_VIDEO_ID", httpRequestConfig, new VideoListener() {
@Override
public void onVideo(Video video) {
// The Video Sources will have a VMAP url which will be processed by the SSAI plugin,
// If there is not a VMAP url, or if there are any requesting or parsing error,
// an EventType.ERROR event will be emitted.
plugin.processVideo(video);
}
});
}
// The setupGoogleIMA method, for reference:
/**
* Setup the Brightcove IMA Plugin.
*/
private void setupGoogleIMA() {
// Establish the Google IMA SDK factory instance.
final ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
// Enable logging up ad start.
eventEmitter.on(EventType.AD_STARTED, new EventListener() {
@Override
public void processEvent(Event event) {
Log.v(TAG, event.getType());
}
});
// Enable logging any failed attempts to play an ad.
eventEmitter.on(GoogleIMAEventType.DID_FAIL_TO_PLAY_AD, new EventListener() {
@Override
public void processEvent(Event event) {
Log.v(TAG, event.getType());
}
});
// Enable Logging upon ad completion.
eventEmitter.on(EventType.AD_COMPLETED, new EventListener() {
@Override
public void processEvent(Event event) {
Log.v(TAG, event.getType());
}
});
// Set up a listener for initializing AdsRequests. The Google
// IMA plugin emits an ad request event as a result of
// initializeAdsRequests() being called.
eventEmitter.on(GoogleIMAEventType.ADS_REQUEST_FOR_VIDEO, new EventListener() {
@Override
public void processEvent(Event event) {
// Create a container object for the ads to be presented.
AdDisplayContainer container = sdkFactory.createAdDisplayContainer();
container.setPlayer(googleIMAComponent.getVideoAdPlayer());
container.setAdContainer(brightcoveVideoView);
// Build an ads request object and point it to the ad
// display container created above.
AdsRequest adsRequest = sdkFactory.createAdsRequest();
adsRequest.setAdTagUrl(adRulesURL);
adsRequest.setAdDisplayContainer(container);
ArrayList<AdsRequest> adsRequests = new ArrayList<AdsRequest>(1);
adsRequests.add(adsRequest);
// Respond to the event with the new ad requests.
event.properties.put(GoogleIMAComponent.ADS_REQUESTS, adsRequests);
eventEmitter.respond(event);
}
});
// Create the Brightcove IMA Plugin and pass in the event
// emitter so that the plugin can integrate with the SDK.
googleIMAComponent = new GoogleIMAComponent(brightcoveVideoView, eventEmitter, true);
}
iOS 實作
對於此功能,您將同時使用 IMA 和 SSAI 外掛程式:
代碼樣本
若要實作此功能,請檢閱下列範例:
- 適用於iOS的IMA實時Live預貼片廣告( SLS_IMA-播放器)
- 用於tvOS的帶有實時SSAI的IMA預卷( SLS_IMA-tvOSPlayer)