diff 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
line wrap: on
line diff
--- a/modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.mm	Thu Feb 02 11:42:53 2017 -0800
+++ b/modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.mm	Thu Feb 02 12:46:31 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -281,12 +281,16 @@
                          change:(NSDictionary *)change
                         context:(void *)context {
     if (context == AVFMediaPlayerItemStatusContext) {
-        AVPlayerStatus status = (AVPlayerStatus)[[change objectForKey:NSKeyValueChangeNewKey] longValue];
-        if (status == AVPlayerStatusReadyToPlay) {
-            if (!_movieReady) {
-                // Only send this once, though we'll receive notification a few times
-                [self setPlayerState:kPlayerState_READY];
-                _movieReady = true;
+        // According to docs change[NSKeyValueChangeNewKey] can be NSNull when player.currentItem is nil
+        if (![change[NSKeyValueChangeNewKey] isKindOfClass:[NSNull class]]) {
+            AVPlayerStatus status = (AVPlayerStatus)[[change objectForKey:NSKeyValueChangeNewKey] longValue];
+            if (status == AVPlayerStatusReadyToPlay) {
+                if (!_movieReady) {
+                    LOGGER_DEBUGMSG(([[NSString stringWithFormat:@"Setting player to READY state"] UTF8String]));
+                    // Only send this once, though we'll receive notification a few times
+                    [self setPlayerState:kPlayerState_READY];
+                    _movieReady = true;
+                }
             }
         }
     } else if (context == AVFMediaPlayerItemDurationContext) {