javauis/amms_qt/javasrc/com/nokia/amms/control/PriorityControl.java
changeset 23 98ccebc37403
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Control for adjusting player priorities.
       
    15 *
       
    16 */
       
    17 
       
    18 package com.nokia.amms.control;
       
    19 
       
    20 import com.nokia.microedition.media.NativeError;
       
    21 import javax.microedition.media.Player;
       
    22 
       
    23 /**
       
    24  * Control for adjusting player priorities.
       
    25  */
       
    26 public class PriorityControl
       
    27         extends ControlImpl
       
    28         implements javax.microedition.amms.control.PriorityControl
       
    29 {
       
    30     private static final int MIN_PRIORITY = 0;
       
    31     private static final int MAX_PRIORITY = 100;
       
    32 
       
    33     // The player owning this control.
       
    34     private Player iPlayer;
       
    35 
       
    36 
       
    37     /**
       
    38      * Constructor
       
    39      */
       
    40     public PriorityControl(Player aPlayer)
       
    41     {
       
    42         iPlayer = aPlayer;
       
    43     }
       
    44 
       
    45     /**
       
    46      * Please refer to JSR 234 for more details.
       
    47      */
       
    48     public void setPriority(int aPriority)
       
    49     {
       
    50         checkValid();
       
    51 
       
    52         int priority = aPriority;
       
    53         // Panning value that is out of range is set to the valid range.
       
    54         if (aPriority < MIN_PRIORITY ||
       
    55                 aPriority > MAX_PRIORITY)
       
    56         {
       
    57             throw new IllegalArgumentException(
       
    58                 "Priority must be between 0 and 100");
       
    59         }
       
    60 
       
    61         // Priority setting in native side returns a system wide error code.
       
    62         int error = _setPriority(iEventSource, iControlHandle, aPriority);
       
    63         NativeError.check(error);
       
    64     }
       
    65 
       
    66     /**
       
    67      * Please refer to JSR 234 for more details.
       
    68      */
       
    69     public int getPriority()
       
    70     {
       
    71         checkValid();
       
    72 
       
    73         int value = _getPriority(iEventSource, iControlHandle);
       
    74 
       
    75         return value;
       
    76     }
       
    77 
       
    78     public void checkValid()
       
    79     {
       
    80         super.checkValid();
       
    81 
       
    82         if (iPlayer.getState() == Player.CLOSED)
       
    83         {
       
    84             throw new IllegalStateException("Player is closed.");
       
    85         }
       
    86     }
       
    87 
       
    88     // native methods
       
    89     private static native int _setPriority(
       
    90         int aEventSource,
       
    91         int aControlHandle,
       
    92         int aPriority);
       
    93     private static native int _getPriority(
       
    94         int aEventSource,
       
    95         int aControlHandle);
       
    96 }