以下是刪除和取代廣告的使用案例:
實作 PTTimeRangeCollection
並將內容範圍標示為廣告:
準備 PTTimeRangeCollection
.
設定型別 PTTimeRangeCollection
至 PTTimeRangeCollectionTypeMarkRanges
.
此步驟會通知TVSDK自訂範圍必須視為廣告。
#define PSDK_TIMESCALE 100000
NSArray *ranges = @[
[PTReplacementRange
replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
(0, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))],
[PTReplacementRange
replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
(120, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))]
];
PTTimeRangeCollection *timeRangeCollection =
[[PTTimeRangeCollection alloc] initWithRanges:ranges
type:PTTimeRangeCollectionTypeMarkRanges];
建立 PTAdMetadata
並設定 PTTimeRangeCollection
.
// Create the PTPlayerItem metadata
PTMetadata *metadata = [[PTMetadata alloc] init];
// Create the Ad metadata
PTAuditudeMetadata *adMetadata = [[PTAuditudeMetadata alloc] init];
adMetadata.timeRangeCollection = timerangeCollection;
//Set Ad metadata
[metadata setMetadata:adMetadata forKey:PTAdResolvingMetadataKey];
//Create PTMediaPlayerItem
PTMediaPlayerItem *playerItem = [[[PTMediaPlayerItem alloc] initWithUrl:mediaUrl
mediaId:mediaId
metadata:metadata];
建立播放器並開始播放。
//Create PTMediaPlayer using the created PTMediaPlayer
PTMediaPlayer *player = [PTMediaPlayer playerWithMediaPlayerItem:playerItem];
//Add player to the player UIView
[self.playerView addSubview:(UIView *)player.view];
//Start playback
[player play];
實作 PTTimeRangeCollection
並將內容範圍刪除為廣告:
準備 PTTimeRangeCollection
.
設定型別 PTTimeRangeCollection
至 PTTimeRangeCollectionTypeReplaceRanges
.
此步驟會通知TVSDK提供的範圍需要取代為替代內容(廣告)。
#define PSDK_TIMESCALE 100000
NSArray *ranges = @[
[PTReplacementRange replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
(0, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))
replacementDuration:CMTimeMakeWithSeconds(30, AD_TIMESCALE)],
[PTReplacementRange replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
(120, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))
replacementDuration:CMTimeMakeWithSeconds(30, AD_TIMESCALE)]
];
PTTimeRangeCollection *timeRangeCollection =
[[PTTimeRangeCollection alloc] initWithRanges:ranges
type:PTTimeRangeCollectionTypeReplaceRanges];
引數 replacementDuration
是選用專案。 如果未定義, AdServer
決定廣告插播的持續時間。
建立 PTAdMetadata
並設定 PTTimeRangeCollection
.
//Create the PTPlayerItem metadata
PTMetadata *metadata = [[PTMetadata alloc] init];
//Create the Ad metadata
PTAuditudeMetadata *adMetadata = [[PTAuditudeMetadata alloc] init];
adMetadata.timeRangeCollection = timerangeCollection;
adMetadata.zoneId = adZoneId;
adMetadata.domain = adDomain;
adMetadata.signalingMode = PTAdSignalingModeCustomRanges;
//Set Ad metadata
[metadata setMetadata:adMetadata forKey:PTAdResolvingMetadataKey];
//Create PTMediaPlayerItem
PTMediaPlayerItem *playerItem = [[[PTMediaPlayerItem alloc] initWithUrl:mediaUrl
mediaId:mediaId
metadata:metadata];
雖然 signalingMode
設為 PTAdSignalingModeCustomRanges
,此廣告訊號模式會在設定 PTTimeRangeCollection
型別 PTTimeRangeCollectionTypeReplace
.
建立播放器並開始播放。
//Create PTMediaPlayer using the created PTMediaPlayer
PTMediaPlayer *player = [PTMediaPlayer playerWithMediaPlayerItem:playerItem];
//Add player to the player UIView
[self.playerView addSubview:(UIView *)player.view];
//Start playback
[player play];
實作 PTTimeRangeCollection
並將內容範圍刪除為廣告:
準備 PTTimeRangeCollection
.
設定型別 PTTimeRangeCollection
至 PTTimeRangeCollectionTypeDeleteRanges
,會通知TVSDK提供的範圍需要刪除。
#define PSDK_TIMESCALE 100000
NSArray *ranges = @[
[PTReplacementRange replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
(0, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))],
[PTReplacementRange replacementRangeWithRange:CMTimeRangeMake(CMTimeMakeWithSeconds
(120, PSDK_TIMESCALE),CMTimeMakeWithSeconds(60, AD_TIMESCALE))]
];
PTTimeRangeCollection *timeRangeCollection =
[[PTTimeRangeCollection alloc] initWithRanges:ranges
type:PTTimeRangeCollectionTypeDeleteRanges];
建立 PTAdMetadata
並設定 PTTimeRangeCollection
.
//Create the PTPlayerItem metadata
PTMetadata *metadata = [[PTMetadata alloc] init];
//Create the Ad metadata
PTAuditudeMetadata *adMetadata = [[PTAuditudeMetadata alloc] init];
adMetadata.timeRangeCollection = timerangeCollection;
adMetadata.zoneId = adZoneId;
adMetadata.domain = adDomain;
adMetadata.signalingMode = PTAdSignalingModeServerMap;
//Set Ad metadata
[metadata setMetadata:adMetadata forKey:PTAdResolvingMetadataKey];
//Create PTMediaPlayerItem
PTMediaPlayerItem *playerItem = [[[PTMediaPlayerItem alloc] initWithUrl:mediaUrl
mediaId:mediaId
metadata:metadata];
廣告插入會在刪除自訂範圍後發生,根據 PTAdMetadata
和目前的 PTAdSignalingMode
.
建立播放器並開始播放。
//Create PTMediaPlayer using the created PTMediaPlayer
PTMediaPlayer *player = [PTMediaPlayer playerWithMediaPlayerItem:playerItem];
//Add player to the player UIView
[self.playerView addSubview:(UIView *)player.view];
//Start playback
[player play];