1 /*
   2  * Copyright (c) 2010, 2013, 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
  23  * questions.
  24  */
  25 
  26 package com.sun.media.jfxmedia;
  27 
  28 import com.sun.media.jfxmedia.events.MediaErrorListener;
  29 import com.sun.media.jfxmedia.locator.Locator;
  30 import com.sun.media.jfxmediaimpl.NativeMediaManager;
  31 import java.util.List;
  32 
  33 /**
  34  * Factory class used to create media objects, players, and recorders, and to
  35  * manage other global functionality.
  36  *
  37  * @see MediaPlayer
  38  * @see MediaRecorder
  39  */
  40 public class MediaManager {
  41 
  42     private MediaManager() {
  43         // prevent instantiation of this class
  44     }
  45 
  46     /**
  47      * @return {@link String} array of supported content types.
  48      */
  49     public static String[] getSupportedContentTypes() {
  50         return NativeMediaManager.getDefaultInstance().getSupportedContentTypes();
  51     }
  52 
  53     /**
  54      * Whether a media source having the indicated content type may be
  55      * played.
  56      *
  57      * @throws IllegalArgumentException if <code>contentType</code> is
  58      * <code>null</code>.
  59      */
  60     public static boolean canPlayContentType (String contentType) {
  61         if (contentType == null) {
  62             throw new IllegalArgumentException("contentType == null!");
  63         }
  64         return NativeMediaManager.getDefaultInstance().canPlayContentType (contentType);
  65     }
  66 
  67 
  68     // XXX javadoc
  69     public static MetadataParser getMetadataParser(Locator locator) {
  70         if (locator == null) {
  71             throw new IllegalArgumentException("locator == null!");
  72         }
  73         return NativeMediaManager.getDefaultInstance().getMetadataParser(locator);
  74     }
  75 
  76     /**
  77      * Gets a Media object for the clip.  It cannot be played without attaching
  78      * to a MediaPlayer.
  79      *
  80      * @param locator
  81      * @return Media object
  82      * @throws IllegalArgumentException if <code>locator</code> is
  83      * <code>null</code>.
  84      */
  85     public static Media getMedia(Locator locator) {
  86         if (locator == null) {
  87             throw new IllegalArgumentException("locator == null!");
  88         }
  89         return NativeMediaManager.getDefaultInstance().getMedia(locator);
  90     }
  91 
  92     /**
  93      * Get a player for the media locator
  94      *
  95      * @param locator
  96      * @return MediaPlayer object
  97      * @throws IllegalArgumentException if <code>locator</code> is
  98      * <code>null</code>.
  99      */
 100     public static MediaPlayer getPlayer(Locator locator) {
 101         if (locator == null) {
 102             throw new IllegalArgumentException("locator == null!");
 103         }
 104         return NativeMediaManager.getDefaultInstance().getPlayer(locator);
 105     }
 106 
 107     /**
 108      * Add a global listener for warnings. This listener will receive warnings
 109      * which occur fall outside the context of a particular player or recorder.
 110      *
 111      * @param listener The listener to add.
 112      * @throws IllegalArgumentException if <code>listener</code> is
 113      * <code>null</code>.
 114      */
 115     public static void addMediaErrorListener(MediaErrorListener listener) {
 116         if (listener == null) {
 117             throw new IllegalArgumentException("listener == null!");
 118         }
 119         NativeMediaManager.getDefaultInstance().addMediaErrorListener(listener);
 120     }
 121 
 122     /**
 123      * Remove a global listener for warnings.
 124      *
 125      * @param listener The listener to remove.
 126      * @throws IllegalArgumentException if <code>listener</code> is
 127      * <code>null</code>.
 128      */
 129     public static void removeMediaErrorListener(MediaErrorListener listener) {
 130         if (listener == null) {
 131             throw new IllegalArgumentException("listener == null!");
 132         }
 133         NativeMediaManager.getDefaultInstance().removeMediaErrorListener(listener);
 134     }
 135 
 136     /**
 137      * This function will register MediaPlayer for disposing when obj parameter
 138      * does not have any strong reference.
 139      *
 140      * @param obj - Object to watch for strong references
 141      * @param player - MediaPlayer to dispose
 142      */
 143     public static void registerMediaPlayerForDispose(Object obj, MediaPlayer player) {
 144         NativeMediaManager.registerMediaPlayerForDispose(obj, player);
 145     }
 146 
 147     /**
 148      * Retrieve all un-disposed {@link MediaPlayer}s.
 149      * @return a {@link List} of all un-disposed players or <code>null</code>.
 150      */
 151     public static List<MediaPlayer> getAllMediaPlayers() {
 152         return NativeMediaManager.getDefaultInstance().getAllMediaPlayers();
 153     }
 154 }