|
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.amms.control; |
|
20 |
|
21 import com.nokia.amms.AMMSError; |
|
22 |
|
23 public class VolumeControl extends ControlImpl |
|
24 implements javax.microedition.media.control.VolumeControl |
|
25 { |
|
26 private static final int MAX_VOLUME = 100; |
|
27 private int iLevel = MAX_VOLUME; |
|
28 private boolean iMuted = false; |
|
29 |
|
30 /** |
|
31 * Constructor |
|
32 */ |
|
33 public VolumeControl() |
|
34 { |
|
35 } |
|
36 |
|
37 /** |
|
38 * Please refer to JSR 234 for more details. |
|
39 */ |
|
40 public boolean isMuted() |
|
41 { |
|
42 checkValid(); |
|
43 return iMuted; |
|
44 } |
|
45 |
|
46 /** |
|
47 * Please refer to JSR 234 for more details. |
|
48 */ |
|
49 public int getLevel() |
|
50 { |
|
51 checkValid(); |
|
52 return iLevel; |
|
53 } |
|
54 |
|
55 /** |
|
56 * Please refer to JSR 234 for more details. |
|
57 */ |
|
58 public int setLevel(int aLevel) |
|
59 { |
|
60 checkValid(); |
|
61 int level = aLevel; |
|
62 |
|
63 // Set level to between 0 and 100 |
|
64 if (level < 0) |
|
65 { |
|
66 level = 0; |
|
67 } |
|
68 else if (level > MAX_VOLUME) |
|
69 { |
|
70 level = MAX_VOLUME; |
|
71 } |
|
72 |
|
73 if (!iMuted) |
|
74 { |
|
75 AMMSError.check(_setLevel(iEventSource, |
|
76 iControlHandle, |
|
77 level)); |
|
78 } |
|
79 iLevel = level; |
|
80 return level; |
|
81 } |
|
82 |
|
83 /** |
|
84 * Please refer to JSR 234 for more details. |
|
85 */ |
|
86 public void setMute(boolean aMuted) |
|
87 { |
|
88 checkValid(); |
|
89 |
|
90 // Check if mute status is changed |
|
91 if (aMuted != iMuted) |
|
92 { |
|
93 iMuted = aMuted; |
|
94 |
|
95 int level = iLevel; |
|
96 |
|
97 // If mute is on set volume to 0, otherwise set to level set before |
|
98 if (iMuted) |
|
99 { |
|
100 level = 0; |
|
101 } |
|
102 |
|
103 AMMSError.check(_setLevel(iEventSource, |
|
104 iControlHandle, |
|
105 level)); |
|
106 } |
|
107 } |
|
108 |
|
109 /** |
|
110 * @param aEventSourceHandle Handle to native event source. |
|
111 * @param aControlHandle Handle to native control. |
|
112 * @param aLevel New volume level. |
|
113 */ |
|
114 private static native int _setLevel(int aEventSourceHandle, |
|
115 int aControlHandle, |
|
116 int aLevel); |
|
117 } |