ios-vast-player
ios-vast-player copied to clipboard
ad1 plays twice at the beginning on iOS 6 Simulator!
Same goes with my client's VAST XML, so it's not your XML but rather the code somewhere which unders iOS 6 plays the first ad twice.
This is only under the simulator, so this is really not a big deal, but I first thought it was also on the device. Wonder why it does that on the sim.
Actually not only in the simulator. What happens is this part of the code get called twice:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
...
else if (context == DVIABContentPlayerRateObservationContext) {
float rate = [[change objectForKey:NSKeyValueChangeNewKey] floatValue];
dispatch_async(dispatch_get_main_queue(), ^{
if (rate > 0) {
self.contentPlayerItemDidReachEnd = NO;
if (CMTimeCompare(CMTimeAbsoluteValue(self.currentItem.currentTime),
CMTimeMake(1, 1)) == -1) {
self.playBreaksQueue = [[self.adPlaylist preRollPlayBreaks] mutableCopy];
[self startPlayBreaksFromQueue];
And thus startPlayBreaksFromQueue
is called twice and since self.playBreaksQueue
is a mutableCopy it doesn't count that the ad is removed from the queue. What do you think we should do? I could have some kind of flag saying the had has been started or use directly self.adPlaylist.preRollPlayBreaks
but I'd have to make it writeable. What do you think?
Also if (CMTimeCompare(CMTimeAbsoluteValue(self.currentItem.currentTime), CMTimeMake(1, 1)) == -1)
seems to mean play before 1 second which might happen more than once. why don't we just play (without checking when) and then remove the observer?
OK here is my proposal: https://github.com/stuffmc/ios-vast-player/commit/030fe3ec986d0d77741f325c6f229ba27dccef6c — removing the observer once "processed".