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.jfxmediaimpl.platform.ios;
  27 
  28 import com.sun.media.jfxmedia.Media;
  29 import com.sun.media.jfxmedia.MediaPlayer;
  30 import com.sun.media.jfxmedia.locator.Locator;
  31 import com.sun.media.jfxmedia.logging.Logger;
  32 import com.sun.media.jfxmediaimpl.HostUtils;
  33 import com.sun.media.jfxmediaimpl.platform.Platform;
  34 
  35 /**
  36  * iOS Platform implementation.
  37  */
  38 public final class IOSPlatform extends Platform {
  39 
  40     /**
  41      * The MIME types of all supported media.
  42      */
  43     private static final String[] CONTENT_TYPES = {
  44         "video/mp4",
  45         "audio/x-m4a",
  46         "video/x-m4v",
  47         "application/vnd.apple.mpegurl",
  48         "audio/mpegurl",
  49         "audio/mpeg",
  50         "audio/mp3",
  51         "audio/x-wav",
  52         "video/quicktime",
  53         "video/x-quicktime",
  54         "audio/x-aiff"
  55     };
  56 
  57     private static final class IOSPlatformInitializer {
  58         private static final IOSPlatform globalInstance = new IOSPlatform();
  59     }
  60 
  61     public static Platform getPlatformInstance() {
  62         return IOSPlatformInitializer.globalInstance;
  63     }
  64 
  65     private IOSPlatform() {
  66     }
  67 
  68     @Override
  69     public void preloadPlatform() {}
  70 
  71     /**
  72      * @return false if the platform cannot be loaded
  73      */
  74     @Override
  75     public boolean loadPlatform() {
  76         if (!HostUtils.isIOS()) {
  77             return false;
  78         }
  79 
  80         try {
  81             iosPlatformInit();
  82         } catch (UnsatisfiedLinkError ule) {
  83             if (Logger.canLog(Logger.DEBUG)) {
  84                 Logger.logMsg(Logger.DEBUG, "Unable to load iOS platform.");
  85             }
  86             //MediaUtils.nativeError(IOSPlatform.class, MediaError.ERROR_MANAGER_ENGINEINIT_FAIL);
  87             return false;
  88         }
  89         return true;
  90     }
  91 
  92     @Override
  93     public String[] getSupportedContentTypes() {
  94         String[] contentTypesCopy = new String[CONTENT_TYPES.length];
  95         System.arraycopy(CONTENT_TYPES, 0, contentTypesCopy, 0, CONTENT_TYPES.length);
  96         return contentTypesCopy;
  97     }
  98 
  99     @Override
 100     public Media createMedia(Locator source) {
 101         return new IOSMedia(source);
 102     }
 103 
 104     @Override
 105     public Object prerollMediaPlayer(Locator source) {
 106         // attempt the actual player creation, then preroll here
 107         // on success we return a reference to the native player as the cookie
 108         return new IOSMediaPlayer(source);
 109     }
 110 
 111     @Override
 112     public MediaPlayer createMediaPlayer(Locator source, Object cookie) {
 113         if (cookie == null) {
 114             throw new NullPointerException("null player!");
 115         }
 116         else if (!(cookie instanceof IOSMediaPlayer)) {
 117             throw new IllegalArgumentException("cookie is not an instance of IOSMediaPlayer");
 118         }
 119 
 120         return (MediaPlayer) cookie;
 121     }
 122 
 123     private static native void iosPlatformInit();
 124 }