javauis/mmapi_qt/baseline/javasrc/com/nokia/microedition/media/NativePlayerFactory.java
branchRCL_3
changeset 24 0fd27995241b
equal deleted inserted replaced
20:f9bb0fca356a 24:0fd27995241b
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.microedition.media;
       
    20 
       
    21 import javax.microedition.media.MediaException;
       
    22 import javax.microedition.media.protocol.DataSource;
       
    23 
       
    24 /**
       
    25  * Factory for creating native and java instances of the players
       
    26  */
       
    27 public class NativePlayerFactory
       
    28 {
       
    29     /**
       
    30      * Do not allow contruction.
       
    31      */
       
    32     private NativePlayerFactory()
       
    33     {
       
    34     }
       
    35 
       
    36     /**
       
    37      * Creates native and java instances with Locator
       
    38      * @param aLocator Locator used for creating native player
       
    39      * @param aSource The DataSource that provides the media content.
       
    40      * @return new instance of <code>InternalPlayer</code>
       
    41      */
       
    42     public static InternalPlayer createPlayer(Locator aLocator,
       
    43             DataSource aSource)
       
    44     throws java.io.IOException,
       
    45                 MediaException,
       
    46                 java.lang.SecurityException
       
    47     {
       
    48         int playerHandle = _createPlayerLocator(ManagerImpl.getEventSource(),
       
    49                                                 ManagerImpl.getHandle(),
       
    50                                                 aLocator.getProtocol(),
       
    51                                                 aLocator.getMiddlePart(),
       
    52                                                 aLocator.getParameters());
       
    53         return createPlayer(playerHandle, aSource);
       
    54     }
       
    55 
       
    56     /**
       
    57      * Creates native and java instances with Locator
       
    58      * @param aLocator Locator used for creating native player
       
    59      * @return new instance of <code>InternalPlayer</code>
       
    60      */
       
    61     public static InternalPlayer createPlayer(Locator aLocator)
       
    62     throws java.io.IOException,
       
    63                 MediaException,
       
    64                 java.lang.SecurityException
       
    65     {
       
    66         return createPlayer(aLocator, null);
       
    67     }
       
    68 
       
    69     /**
       
    70      * Creates native and java instances with content-type
       
    71      * @param aContentType Content type for creating native counter-part
       
    72      * @param aSource The DataSource that provides the media content.
       
    73      * @return new instance of <code>InternalPlayer</code>
       
    74      */
       
    75     public static InternalPlayer createPlayer(String aContentType,
       
    76             DataSource aSource)
       
    77     throws java.io.IOException,
       
    78                 MediaException,
       
    79                 java.lang.SecurityException
       
    80     {
       
    81         int playerHandle = _createPlayerContentType(ManagerImpl.getEventSource(),
       
    82                            ManagerImpl.getHandle(),
       
    83                            aContentType);
       
    84         return createPlayer(playerHandle, aSource);
       
    85     }
       
    86 
       
    87     /**
       
    88      * Creates native and java instances with header data
       
    89      * @param aHeaderData HeaderData used for recognizing content
       
    90      * @param aSource The DataSource that provides the media content.
       
    91      * @return new instance of <code>InternalPlayer</code>
       
    92      */
       
    93     public static InternalPlayer createPlayer(byte[] aHeaderData,
       
    94             DataSource aSource)
       
    95     throws java.io.IOException,
       
    96                 MediaException,
       
    97                 java.lang.SecurityException
       
    98     {
       
    99         int playerHandle = _createPlayerHeaderData(ManagerImpl.getEventSource(),
       
   100                            ManagerImpl.getHandle(),
       
   101                            aHeaderData);
       
   102         return createPlayer(playerHandle, aSource);
       
   103     }
       
   104 
       
   105     /**
       
   106      * Creates java instance from native handle and DataSource
       
   107      */
       
   108     private static InternalPlayer createPlayer(int aPlayerHandle,
       
   109             DataSource aSource)
       
   110     throws java.io.IOException,
       
   111                 MediaException,
       
   112                 java.lang.SecurityException
       
   113     {
       
   114         // if aPlayerHandle is 0 null will be returned
       
   115         InternalPlayer player = null;
       
   116 
       
   117         if (aPlayerHandle < 0)
       
   118         {
       
   119             // negative handle indicates native error code
       
   120             throw new MediaException(
       
   121                 "Could not create player, Symbian OS error: " +
       
   122                 aPlayerHandle);
       
   123         }
       
   124         else if (aPlayerHandle > 0)
       
   125         {
       
   126             // Native player was created
       
   127             if (aSource == null)
       
   128             {
       
   129                 player = new PlayerImpl(aPlayerHandle);
       
   130             }
       
   131             else
       
   132             {
       
   133                 player = new SourcePlayer(aSource, aPlayerHandle);
       
   134             }
       
   135         }
       
   136         return player;
       
   137     }
       
   138 
       
   139     private static native int _createPlayerLocator(int aEventSource,
       
   140             int aManagerHandle,
       
   141             String aProtocol,
       
   142             String aMiddlePart,
       
   143             String aParameters);
       
   144 
       
   145     private static native int _createPlayerContentType(int aEventSource,
       
   146             int aManagerHandle,
       
   147             String aContentType);
       
   148 
       
   149     private static native int _createPlayerHeaderData(int aEventSource,
       
   150             int aManagerHandle,
       
   151             byte[] aHeaderData);
       
   152 }