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.Network.Bluetooth
22 /// This class is used to handle the connection with other Bluetooth audio devices
23 /// like headset, hands-free, and headphone.
25 /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
26 /// <since_tizen> 3 </since_tizen>
27 public class BluetoothAudio : BluetoothProfile
29 internal BluetoothAudio()
34 /// The AudioConnectionStateChanged event is called when the audio connection state is changed.
36 /// <since_tizen> 3 </since_tizen>
37 public event EventHandler<AudioConnectionStateChangedEventArgs> AudioConnectionStateChanged
41 BluetoothAudioImpl.Instance.AudioConnectionStateChanged += value;
45 BluetoothAudioImpl.Instance.AudioConnectionStateChanged -= value;
50 /// Connects the remote device with the given audio profile.
53 /// The device must be bonded with the remote device by CreateBond(). If connection request succeeds, the AudioConnectionStateChanged event will be invoked.
54 /// If audio profile type is All and this request succeeds, then the AudioConnectionStateChanged event will be called twice when HspHfp <br/>
55 /// and AdvancedAudioDistribution is connected.
57 /// <param name="profileType">The type of the audio profile.</param>
58 /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
59 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled
60 /// or when the connection attempt fails.</exception>
61 /// <since_tizen> 3 </since_tizen>
62 public void Connect(BluetoothAudioProfileType profileType)
64 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
66 int ret = BluetoothAudioImpl.Instance.Connect(RemoteAddress, profileType);
67 if (ret != (int)BluetoothError.None)
69 Log.Error(Globals.LogTag, "Failed to Connect - " + (BluetoothError)ret);
70 BluetoothErrorFactory.ThrowBluetoothException(ret);
75 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
80 /// Disconnects the remote device with the given audio profile.
83 /// The device must be connected by Connect(). If the disconnection request succeeds, the AudioConnectionStateChanged event will be invoked.
84 /// If audio profile type is All and this request succeeds, then the AudioConnectionStateChanged event will be called twice when HspHfp <br/>
85 /// and AdvancedAudioDistribution is disconnected.
87 /// <param name="type">The type of the audio profile.</param>
88 /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
89 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled
90 /// or when Disconnection attempt fails.</exception>
91 /// <since_tizen> 3 </since_tizen>
92 public void Disconnect(BluetoothAudioProfileType type)
94 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
96 int ret = BluetoothAudioImpl.Instance.Disconnect(RemoteAddress, type);
97 if (ret != (int)BluetoothError.None)
99 Log.Error(Globals.LogTag, "Failed to Disconnect - " + (BluetoothError)ret);
100 BluetoothErrorFactory.ThrowBluetoothException(ret);
105 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);