Play music with BlueZ A2DP profile

Source: Internet
Author: User

Bluetooth supports two types of profiles to play music, namely, HSP and A2DP. HSP (handset profile) is mono, and the A2DP is two-channel. This article mainly introduces how to play music with A2DP under Linux.

Ready to

1. A Bluetooth headset and a Linux machine will install BlueZ and PulseAudio on Linux by default.

2. Download a long period of WAV audio files, the test will be used.

3. Make sure your Bluetooth headset and PC are paired successfully. If not, you can find headphones and pair them through the Bluetooth-applet interface. Configuration

1. In/ETC/PULSE/DEFAULT.PA, comment out the following two lines

Bluetooth-discover
Module-suspend-on-idle

2. Play a longer form of WAV music.

Paplay 75.wav

3. Use Pacmd to view the index of the input, in the following example, index is 2.

xxx@xxx:~/$ Pacmd
>>> list-sink-inputs
1 sink input (s) available.
Index:2
Driver
Flags
State:running
Sink:1
volume:0:100% 1:100%
0:0.00 DB 1:0.00 db
Balance 0.00
Muted:no
Current latency:1997.28 ms
Requested latency:39.51 MS
Sample Spec:alaw 2ch 44100Hz
Channel Map:front-left,front-right
Stereo
Resample method:copy
Module:7
Client:6
Properties
Media.format = "WAV (Microsoft)"
Application.Name = "Paplay"
Media.name = "75.wav"
Native-protocol.peer = "UNIX Socket client"
Native-protocol.version = "16"
Application.process.id = "6509"
Application.process.user = "XXX"
Application.process.host = "Xxx-host"
Application.process.binary = "Pacat"
Application.language = "En_us.utf8"
Window.x11.display = ": 0.0"
application.process.machine_id = "aed85c03e5ef20ad3d980db14b34d474"
application.process.session_id = "aed85c03e5ef20ad3d980db14b34d474-1283675281.437759-895707289"
Module-stream-restore.id = "Sink-input-by-application-name:paplay"

4. Connect headphones with Test-audio script. In the following example, the address of the headset (BDADDR) is 00:16:44:21:8d:91.

CD bluez/test;

~bluez/test$./test-audio Connect 00:16:44:21:8d:91

5. Load Module-bluetooth-device module under PulseAudio console

>>> load-module module-bluetooth-device profile= "A2DP" address= "00:16:44:21:8d:91"

In the example above, we used the A2DP profile to load the Bluetooth module, and to use HSP, replace the parameter with profile= "HSP".

6. Under the PulseAudio console, List-sink can display a Bluetooth device. In the following example, index is 1.

>>>list-sinks
Index:1
Name
Driver
Flags:hardware Decibel_volume Latency
State:running
Suspend cause:
priority:9030
volume:0:7% 1:7%
0: -70.57 DB 1: -70.57 db
Balance 0.00
Base volume:100%
0.00 DB
Volume steps:65537
Muted:no
Current latency:44.27 ms
Max Request:2 KiB
Max rewind:0 KiB
Monitor Source:2
Sample Spec:s16le 2ch 44100Hz
Channel Map:front-left,front-right
Stereo
Used By:1
Linked By:1
Fixed latency:39.51 ms
Card:1
Module:16
Properties
Bluetooth.protocol = "A2DP"
Device.description = "DELL BH200"
device.string = "00:16:44:21:8d:91"
Device.api = "BlueZ"
Device.class = "Sound"
Device.bus = "Bluetooth"
Device.form_factor = "Headset"
Bluez.path = "/org/bluez/5373/hci0/dev_00_16_44_21_8d_91"
Bluez.class = "0x640404"
Bluez.name = "DELL BH200"
Device.icon_name = "Audio-headset-bluetooth"

7. Under the PulseAudio console, the move-sink-input can be used to guide the voice to the Bluetooth headset.

>>> Move-sink-input 2 1

Well, you should be able to hear the music from the Bluetooth headset. ;-)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.