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 public class BluetoothAudio : BluetoothProfile
28 internal BluetoothAudio()
33 /// The AudioConnectionStateChanged event is called when the audio connection state is changed.
35 public event EventHandler<AudioConnectionStateChangedEventArgs> AudioConnectionStateChanged
39 BluetoothAudioImpl.Instance.AudioConnectionStateChanged += value;
43 BluetoothAudioImpl.Instance.AudioConnectionStateChanged -= value;
48 /// Connects the remote device with the given audio profile.
51 /// The device must be bonded with the remote device by CreateBond(). If connection request succeeds, the AudioConnectionStateChanged event will be invoked.
52 /// If audio profile type is All and this request succeeds, then the AudioConnectionStateChanged event will be called twice when HspHfp <br>
53 /// and AdvancedAudioDistribution is connected.
55 /// <param name="profileType">The type of the audio profile.</param>
56 /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
57 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled
58 /// or when the connection attempt fails.</exception>
59 public void Connect(BluetoothAudioProfileType profileType)
61 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
63 int ret = BluetoothAudioImpl.Instance.Connect(RemoteAddress, profileType);
64 if (ret != (int)BluetoothError.None)
66 Log.Error(Globals.LogTag, "Failed to Connect - " + (BluetoothError)ret);
67 BluetoothErrorFactory.ThrowBluetoothException(ret);
72 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
77 /// Disconnects the remote device with the given audio profile.
80 /// The device must be connected by Connect(). If the disconnection request succeeds, the AudioConnectionStateChanged event will be invoked.
81 /// If audio profile type is All and this request succeeds, then the AudioConnectionStateChanged event will be called twice when HspHfp <br>
82 /// and AdvancedAudioDistribution is disconnected.
84 /// <param name="type">The type of the audio profile.</param>
85 /// <exception cref="NotSupportedException">Thrown when the Bluetooth is not supported.</exception>
86 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth is not enabled
87 /// or when Disconnection attempt fails.</exception>
88 public void Disconnect(BluetoothAudioProfileType type)
90 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
92 int ret = BluetoothAudioImpl.Instance.Disconnect(RemoteAddress, type);
93 if (ret != (int)BluetoothError.None)
95 Log.Error(Globals.LogTag, "Failed to Disconnect - " + (BluetoothError)ret);
96 BluetoothErrorFactory.ThrowBluetoothException(ret);
101 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);