modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaManager.java

Print this page

       

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2015, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -65,10 +65,12 @@
 
     // cached content types, so we don't have to poll and sort each time, this list
     // should never change once we're initialized
     private final List<String> supportedContentTypes =
             new ArrayList();
+    private final List<String> supportedProtocols =
+            new ArrayList<>();
 
     /**
      * The NativeMediaManager singleton.
      */
     private static class NativeMediaManagerInitializer {

@@ -162,10 +164,32 @@
             }
             Logger.logMsg(Logger.DEBUG, sb.toString());
         }
     }
 
+    private synchronized void loadProtocols() {
+        if (!supportedProtocols.isEmpty()) {
+            // already populated, just return
+            return;
+        }
+
+        List<String> npt = PlatformManager.getManager().getSupportedProtocols();
+        if (null != npt && !npt.isEmpty()) {
+            supportedProtocols.addAll(npt);
+        }
+
+        if (Logger.canLog(Logger.DEBUG)) {
+            StringBuilder sb = new StringBuilder("JFXMedia supported protocols:\n");
+            for (String type : supportedProtocols) {
+                sb.append("    ");
+                sb.append(type);
+                sb.append("\n");
+            }
+            Logger.logMsg(Logger.DEBUG, sb.toString());
+        }
+    }
+
     /**
      * Whether a media source having the indicated content type may be played.
      *
      * @see MediaManager#canPlayContentType(java.lang.String)
      *

@@ -193,23 +217,49 @@
         }
 
         return false;
     }
 
-    /**
-     * Returns a copy of the array of supported content types.
-     *
-     * @return {@link String} array of supported content types.
-     */
     public String[] getSupportedContentTypes() {
         if (supportedContentTypes.isEmpty()) {
             loadContentTypes();
         }
 
         return supportedContentTypes.toArray(new String[1]);
     }
 
+    /**
+     * Whether a media source having the indicated protocol may be played.
+     *
+     * @see MediaManager#canPlayProtocol(java.lang.String)
+     *
+     * @throws IllegalArgumentException if
+     * <code>protocol</code> is
+     * <code>null</code>.
+     */
+    public boolean canPlayProtocol(String protocol) {
+        if (protocol == null) {
+            throw new IllegalArgumentException("protocol == null!");
+        }
+
+        if (supportedProtocols.isEmpty()) {
+            loadProtocols();
+        }
+
+        /*
+         * Don't just use supportedProtocols.contains(protocol) as that
+         * is case sensitive, which we do not want
+         */
+        for (String type : supportedProtocols) {
+            if (protocol.equalsIgnoreCase(type)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     public static MetadataParser getMetadataParser(Locator locator) {
         return PlatformManager.getManager().createMetadataParser(locator);
     }
 
     /**