javauis/mmapi_qt/baseline/javasrc/com/nokia/mj/impl/properties/mobilemedia/DynamicPropertyHandler.java
changeset 23 98ccebc37403
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     1 /*
       
     2 * Copyright (c) 2007 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 package com.nokia.mj.impl.properties.mobilemedia;
       
    19 
       
    20 import com.nokia.mj.impl.rt.support.SystemPropertyProvider;
       
    21 import javax.microedition.media.Manager;
       
    22 
       
    23 /**
       
    24  * A class for handling dynamic system properties of MobileMedia API.
       
    25  */
       
    26 public class DynamicPropertyHandler implements SystemPropertyProvider
       
    27 {
       
    28 
       
    29     /*
       
    30      * Constants for identifying the asked property.
       
    31      */
       
    32     private static String AUDIO_ENCODINGS = "audio.encodings";
       
    33     private static String SUPPORTS_VIDEO_CAPTURE = "supports.video.capture";
       
    34     private static String VIDEO_ENCODINGS = "video.encodings";
       
    35 
       
    36     // start of the audio content types
       
    37     private static final String AUDIO = "audio";
       
    38 
       
    39     // special audio encoding strings which are defined in the JSR
       
    40     private static final String AUDIO_ENCODINGS_JSR =
       
    41         " encoding=pcm encoding=ulaw encoding=gsm";
       
    42 
       
    43     // start of the video content types
       
    44     private static final String VIDEO = "video";
       
    45 
       
    46 
       
    47     /* (non-Javadoc)
       
    48      * @see com.nokia.mj.impl.rt.DynamicProperty#getProperty(com.nokia.mj.impl.rt.DynamicPropertyInfo)
       
    49      */
       
    50     public String getProperty(String propertyName)
       
    51     {
       
    52         String propertyValue = null;
       
    53 
       
    54         if (propertyName.equals(AUDIO_ENCODINGS))
       
    55         {
       
    56             propertyValue = getSupportedCaptureEncodings(AUDIO) +
       
    57                             AUDIO_ENCODINGS_JSR;
       
    58         }
       
    59         else if (propertyName.equals(SUPPORTS_VIDEO_CAPTURE))
       
    60         {
       
    61             propertyValue = getSupportedCaptureEncodings(VIDEO);
       
    62             // video capture is supported only if there is supported encodings
       
    63             propertyValue = String.valueOf(propertyValue != null);
       
    64         }
       
    65         else if (propertyName.equals(VIDEO_ENCODINGS))
       
    66         {
       
    67             propertyValue = getSupportedCaptureEncodings(VIDEO);
       
    68         }
       
    69         return propertyValue;
       
    70     }
       
    71 
       
    72     public boolean isStatic(String key)
       
    73     {
       
    74         // All property values of MobileMedia API do not change during the
       
    75         // lifetime of the application.
       
    76         return true;
       
    77     }
       
    78 
       
    79     // capture protocol
       
    80     private static final String CAPTURE = "capture";
       
    81 
       
    82     // encoding for media strings
       
    83     private static final String ENCODING = "encoding=";
       
    84 
       
    85     /**
       
    86      * Returns supported capture encodings.
       
    87      * @param aPrefix Capture format type.
       
    88      * @return the supported capture encodings.
       
    89      */
       
    90     private String getSupportedCaptureEncodings(String aPrefix)
       
    91     {
       
    92         // get supported content types from all capture:// protocols
       
    93         String[] cTypes = Manager.getSupportedContentTypes(CAPTURE);
       
    94 
       
    95         StringBuffer sBuffer = new StringBuffer();
       
    96 
       
    97         // go through all types
       
    98         for (int i = 0; i < cTypes.length; i++)
       
    99         {
       
   100             if (cTypes[ i ].startsWith(aPrefix))
       
   101             {
       
   102                 // if video type appent to buffer encoding= + content type
       
   103                 sBuffer.append(ENCODING + cTypes[ i ] + " ");
       
   104             }
       
   105         }
       
   106         String encodings = null;
       
   107 
       
   108         // if no types was found null must be returned
       
   109         if (sBuffer.length() > 0)
       
   110         {
       
   111             // substring is taken to remove last empty space added in previous
       
   112             // for loop
       
   113             encodings = sBuffer.toString().substring(0,
       
   114                         sBuffer.length() - 1);
       
   115         }
       
   116         return encodings;
       
   117     }
       
   118 }