IMA SDK는 실시간 스트림 및 VOD로 수익을 창출하는 데 사용할 수 있습니다. 라이브 스트림의 경우 각 광고 시점에 대해 새로운 광고 요청을 해야 합니다. 모든 시청자가 요청하지 않도록 시차를 두고 요청을 보내세요. 광고를 동시에 게재하며 광고 서버를 지연시킬 수 있습니다.
이를 위해 IMA SDK에는 AdsRequest.liveStreamPrefetchSeconds
속성 이 속성은 SDK의 최대 시간(초)을 지정합니다.
호출한 후 광고 서버에 연결하기 전에 대기해야 합니다.
AdsLoader.requestAds()
실제 요청 시간은 무작위로 지정됩니다. 대상
예를 들어 AdsRequest.liveStreamPrefetchSeconds
를 30으로 설정하면 SDK는
실제로 사용자가 실제로 실행하기 위해 AdsLoader.requestAds()
를 호출한 후 0~30초 동안
서버에 요청할 수 있습니다
라이브 스트림 프리패치의 실제 사용 사례
광고 시점이 완료되는 즉시 다음 광고 시점을 미리 가져오는 것이 좋습니다. 이렇게 하면 프리패치 기간에 사용할 수 있는 최대 시간이 보장됩니다. 다음 광고 시점 사이에 5분의 간격이 있다고 가정해 보겠습니다. 광고 시점이 완료되면 프리패치 기간 290초로 다음 광고 시점을 요청할 수 있습니다 (5분에서 10초를 뺀 값, 프리페치 창에서 해결할 수 있는 충분한 시간이 있습니다.
다음 코드 스니펫은 실시간 스트림 프리페치를 고급 예 를 지원하지만 이 접근 방식은 다른 IMA 구현에 적용될 수 있습니다.
VideoPlayerController.java
/** Ads logic for handling the IMA SDK integration code and events. */
public class VideoPlayerController {
// 5 minutes == 300 seconds. Include a 10 second buffer
private float AD_INTERVAL = 290;
private double AD_TIMEOUT = 300;
...
adsManager.addAdEventListener(
new AdEvent.AdEventListener() {
/** Responds to AdEvents. */
@Override
public void onAdEvent(AdEvent adEvent) {
...
case ALL_ADS_COMPLETED:
if (adsManager != null) {
adsManager.destroy();
adsManager = null;
}
// When pre-fetching for live streams, be sure to destroy the current AdsManager,
// in case the tag you requested previously contains post-rolls
// (you don't want to play those now).
// Pre-fetch the next ad break.
// Play those ads in ~5 minutes. In a real-world implementation,
// this will likely be done as the result of a message from your
// streaming server, not a via the playAdsAfterThisTime parameter
// of requestAndPlayAds().
requestAndPlayAds(AD_TIMEOUT);
break;
default:
break;
}
}
...
public void requestAndPlayAds(double playAdsAfterThisTime) {
if (currentAdTagUrl == null || currentAdTagUrl == "") {
log("No VAST ad tag URL specified");
resumeContent();
return;
}
// Since you're switching to a new video, tell the SDK the previous video is finished.
if (adsManager != null) {
adsManager.destroy();
}
playButton.setVisibility(View.GONE);
// Create the ads request.
AdsRequest request = sdkFactory.createAdsRequest();
request.setAdTagUrl(currentAdTagUrl);
request.setContentProgressProvider(videoPlayerWithAdPlayback.getContentProgressProvider());
request.setLiveStreamPrefetchSeconds(AD_INTERVAL);
playAdsAfterTime = playAdsAfterThisTime;
// Request the ad. After the ad is loaded, onAdsManagerLoaded() will be called.
adsLoader.requestAds(request);
}