comparison modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.mm @ 10315:020fbca40bf9

8170630: [MacOSX] Media crash NSInvalidArgumentException playing some video Reviewed-by: ddehaven
author almatvee
date Thu, 02 Feb 2017 12:46:31 -0800
parents 1143dd8b53d8
children f35915708e0c
comparison
equal deleted inserted replaced
1:358ffb7d2663 2:6ea4d00b08ab
1 /* 1 /*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
279 - (void) observeValueForKeyPath:(NSString *)keyPath 279 - (void) observeValueForKeyPath:(NSString *)keyPath
280 ofObject:(id)object 280 ofObject:(id)object
281 change:(NSDictionary *)change 281 change:(NSDictionary *)change
282 context:(void *)context { 282 context:(void *)context {
283 if (context == AVFMediaPlayerItemStatusContext) { 283 if (context == AVFMediaPlayerItemStatusContext) {
284 AVPlayerStatus status = (AVPlayerStatus)[[change objectForKey:NSKeyValueChangeNewKey] longValue]; 284 // According to docs change[NSKeyValueChangeNewKey] can be NSNull when player.currentItem is nil
285 if (status == AVPlayerStatusReadyToPlay) { 285 if (![change[NSKeyValueChangeNewKey] isKindOfClass:[NSNull class]]) {
286 if (!_movieReady) { 286 AVPlayerStatus status = (AVPlayerStatus)[[change objectForKey:NSKeyValueChangeNewKey] longValue];
287 // Only send this once, though we'll receive notification a few times 287 if (status == AVPlayerStatusReadyToPlay) {
288 [self setPlayerState:kPlayerState_READY]; 288 if (!_movieReady) {
289 _movieReady = true; 289 LOGGER_DEBUGMSG(([[NSString stringWithFormat:@"Setting player to READY state"] UTF8String]));
290 // Only send this once, though we'll receive notification a few times
291 [self setPlayerState:kPlayerState_READY];
292 _movieReady = true;
293 }
290 } 294 }
291 } 295 }
292 } else if (context == AVFMediaPlayerItemDurationContext) { 296 } else if (context == AVFMediaPlayerItemDurationContext) {
293 // send update duration event 297 // send update duration event
294 double duration = CMTimeGetSeconds(_player.currentItem.duration); 298 double duration = CMTimeGetSeconds(_player.currentItem.duration);