2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Multimedia
22 /// Provides a means to control volume levels.
24 /// <since_tizen> 3 </since_tizen>
25 public class VolumeLevel
27 internal VolumeLevel()
32 /// Gets or sets the volume level of the specified <see cref="AudioVolumeType"/>.
34 /// <param name="type">The <see cref="AudioVolumeType"/> to control.</param>
35 /// <value>The current volume level.</value>
36 /// <remarks>To set volumes, the specified privilege is required.</remarks>
37 /// <privilege>http://tizen.org/privilege/volume.set</privilege>
38 /// <exception cref="ArgumentException"><paramref name="type"/> is invalid.</exception>
39 /// <exception cref="ArgumentOutOfRangeException">
40 /// <paramref name="type"/> is <see cref="AudioVolumeType.None"/>.<br/>
42 /// <paramref name="value"/> is less than zero.<br/>
44 /// <paramref name="value"/> is greater than <see cref="MaxVolumeLevel.this[AudioVolumeType]"/>.
46 /// <exception cref="UnauthorizedAccessException">The caller does not have required privilege to set volume.</exception>
47 /// <since_tizen> 3 </since_tizen>
48 public int this[AudioVolumeType type]
52 ValidationUtil.ValidateEnum(typeof(AudioVolumeType), type, nameof(type));
54 if (type == AudioVolumeType.None)
56 throw new ArgumentOutOfRangeException(nameof(type),
57 "Cannot get volume level for AudioVolumeType.None");
60 Interop.AudioVolume.GetVolume(type, out var volume).ThrowIfError("Failed to get the volume level");
66 ValidationUtil.ValidateEnum(typeof(AudioVolumeType), type, nameof(value));
68 if (type == AudioVolumeType.None)
70 throw new ArgumentOutOfRangeException(nameof(type),
71 "Cannot set volume level for AudioVolumeType.None");
74 var ret = Interop.AudioVolume.SetVolume(type, value);
76 if (ret == AudioManagerError.InvalidParameter)
78 throw new ArgumentOutOfRangeException(nameof(value), value,
79 $"valid volume level range is 0 <= x <= {nameof(MaxVolumeLevel)}[{nameof(AudioVolumeType)}]");
82 ret.ThrowIfError("Failed to set the volume level");