刪除和替換廣告的示例

以下是刪除和取代廣告的程式範例。

以下是使用DELETE_RANGE的範例:

// Assume that the 3 timerange specs are obtained through external means,
// like a CMS. Assume mediaPlayer is an instance of a properly configured MediaPlayer
// Use these 3 timerange specs to populate the RepaceTimeRange list
List<ReplaceTimeRange> timeRanges = new ArrayList<ReplaceTimeRange>();
timeRanges.add(new ReplaceTimeRange(0,10000, 0));
timeRanges.add(new ReplaceTimeRange(15000,20000, 0));
timeRanges.add(new ReplaceTimeRange(25000,30000, o));

CustomRangeMetadata customRangeMetadata = new CustomRangeMetadata();
customRangeMetadata.setTimeRangeList(timeRanges);
customRangeMetadata.setType(CustomRangeMetadata.CustomRangeType.DELETE_RANGE);

// create a MediaResource instance
MediaResource mediaResource = ... ;

// create a MediaPlayerItemConfig instance
MediaPlayerItemConfig config =
  new MediaPlayerItemConfig(getActivity().getApplicationContext());

// Set customRangeMetadata
config.setCustomRangeMetadata(customRangeMetadata);

// prepare the content for playback by calling replaceCurrentResource
mediaPlayer.replaceCurrentResource(mediaResource, config);

以下是使用REPLACE_RANGE的範例:

// Assume that the 3 timerange specs are obtained through external means, like
//  a CMS. Assume mediaPlayer is an instance of a properly configured MediaPlayer
// Use these 3 timerange specs to populate the RepaceTimeRange list
List<ReplaceTimeRange> timeRanges = new ArrayList<ReplaceTimeRange>();
timeRanges.add(new ReplaceTimeRange(0,10000, 10000));
timeRanges.add(new ReplaceTimeRange(15000,20000, 20000));
timeRanges.add(new ReplaceTimeRange(25000,30000, 30000));

CustomRangeMetadata customRangeMetadata = new CustomRangeMetadata();
customRangeMetadata.setTimeRangeList(timeRanges);
customRangeMetadata.setType(CustomRangeMetadata.CustomRangeType.REPLACE_RANGE);

// create a MediaResource instance
MediaResource mediaResource = ... ;

// create a MediaPlayerItemConfig instance
MediaPlayerItemConfig config = new MediaPlayerItemConfig(getActivity()
    .getApplicationContext());

// Set Auditude settings, which are used for ad replacement, for this
//  MediaPlayerItemConfig instance,

...

// Set customRangeMetadata
config.setCustomRangeMetadata(customRangeMetadata);

// prepare the content for playback by calling replaceCurrentResource
mediaPlayer.replaceCurrentResource(mediaResource, config);

本頁內容