< prev index next >

modules/javafx.media/src/main/java/com/sun/media/jfxmedia/locator/Locator.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 400                                 locatorConnection = getConnection(uri, "GET");
 401                             }
 402 
 403                             if (locatorConnection != null && locatorConnection.connection != null) {
 404                                 isConnected = true;
 405 
 406                                 // Get content type.
 407                                 contentType = locatorConnection.connection.getContentType();
 408                                 contentLength = getContentLengthLong(locatorConnection.connection);
 409 
 410                                 // Disconnect.
 411                                 closeConnection(locatorConnection.connection);
 412                                 locatorConnection.connection = null;
 413                             } else if (locatorConnection != null) {
 414                                 if (locatorConnection.responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
 415                                     isMediaUnAvailable = true;
 416                                 }
 417                             }
 418 
 419                             // FIXME: get cache settings from server, honor them
 420                         } else if (scheme.equals("file") || scheme.equals("jar")) {
 421                             InputStream stream = getInputStream(uri);
 422                             stream.close();
 423                             isConnected = true;
 424                             contentType = MediaUtils.filenameToContentType(uriString); // We need to provide at least something
 425                         }
 426 
 427                         if (isConnected) {
 428                             // Check whether content may be played.
 429                             // For WAV use file signature, since it can detect audio format
 430                             // and we can fail sooner, then doing it at runtime.
 431                             // This is important for AudioClip.
 432                             if (MediaUtils.CONTENT_TYPE_WAV.equals(contentType)) {
 433                                 contentType = getContentTypeFromFileSignature(uri);
 434                                 if (!MediaManager.canPlayContentType(contentType)) {
 435                                     isMediaSupported = false;
 436                                 }
 437                             } else {
 438                                 if (contentType == null || !MediaManager.canPlayContentType(contentType)) {
 439                                     // Try content based on file name.
 440                                     contentType = MediaUtils.filenameToContentType(uriString);


   1 /*
   2  * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 400                                 locatorConnection = getConnection(uri, "GET");
 401                             }
 402 
 403                             if (locatorConnection != null && locatorConnection.connection != null) {
 404                                 isConnected = true;
 405 
 406                                 // Get content type.
 407                                 contentType = locatorConnection.connection.getContentType();
 408                                 contentLength = getContentLengthLong(locatorConnection.connection);
 409 
 410                                 // Disconnect.
 411                                 closeConnection(locatorConnection.connection);
 412                                 locatorConnection.connection = null;
 413                             } else if (locatorConnection != null) {
 414                                 if (locatorConnection.responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
 415                                     isMediaUnAvailable = true;
 416                                 }
 417                             }
 418 
 419                             // FIXME: get cache settings from server, honor them
 420                         } else if (scheme.equals("file") || scheme.equals("jar") || scheme.equals("jrt")) {
 421                             InputStream stream = getInputStream(uri);
 422                             stream.close();
 423                             isConnected = true;
 424                             contentType = MediaUtils.filenameToContentType(uriString); // We need to provide at least something
 425                         }
 426 
 427                         if (isConnected) {
 428                             // Check whether content may be played.
 429                             // For WAV use file signature, since it can detect audio format
 430                             // and we can fail sooner, then doing it at runtime.
 431                             // This is important for AudioClip.
 432                             if (MediaUtils.CONTENT_TYPE_WAV.equals(contentType)) {
 433                                 contentType = getContentTypeFromFileSignature(uri);
 434                                 if (!MediaManager.canPlayContentType(contentType)) {
 435                                     isMediaSupported = false;
 436                                 }
 437                             } else {
 438                                 if (contentType == null || !MediaManager.canPlayContentType(contentType)) {
 439                                     // Try content based on file name.
 440                                     contentType = MediaUtils.filenameToContentType(uriString);


< prev index next >