BT Music Source Example

Source code path: example/bt/music_source

Supported Platforms

  • eh-lb525

  • eh-lb563

  • eh-lb567

  • eh-lb58x

Overview

This example demonstrates local music playback and audio streaming to A2DP SINK devices such as headphones after connection, including:

  • Pre-installed mp3 audio file in the root partition.

Example Usage

The example will enable Bluetooth by default at startup and is controlled via FINSH commands:

  1. Play local music: Use the command music play_default to play the pre-installed .mp3 file. If no Bluetooth devices like headphones are connected, audio will be output directly from the speaker. To play songs from the file system, use music play [loop_time] [path], for example music play 3 \A.mp3 will play A.mp3 from the root partition 3 times.

  2. Search for Bluetooth devices: Use the command music inquiry start to search for headphone-type Bluetooth devices. This command will only report devices with COD Major Class 0x000400 (Audio device). Found devices will be printed in the format “device [%s] searched” and “device COD is [%d], addr is xx:xx:xx:xx:xx:xx”.

  3. Connect to Bluetooth devices: Use the command music conn [addr] to connect, where addr is the address (xx:xx:xx:xx:xx:xx) of the device found above - simply copy the printed value. If you already know the address of a headphone-type Bluetooth device, you can connect directly without searching. When the A2DP profile is connected, the device’s audio output will automatically switch from speaker to headphones, and switch back when disconnected.

  4. Adjust remote Bluetooth device volume: Use the command music set_vol [val] where val is valid between 0-127. This example currently only supports adjusting the volume of headphones that support absolute volume functionality. If the headphones don’t support this feature, volume adjustment will not be possible.

Hardware Requirements

Before running this example, you need to prepare:

Compilation and Flashing

Switch to the example project directory and run the scons command to compile:

> scons --board=eh-lb525 -j32

Switch to the example project/build_xx directory and run uart_download.bat, then select the port as prompted to download:

$ ./uart_download.bat

     Uart Download

please input the serial port num:5

For detailed steps on compilation and downloading, please refer to the related introduction in Quick Start.

Expected Results

After the example starts:

  1. Play built-in music without Bluetooth connection

  2. Can search for headphone-type Bluetooth devices and play built-in music after connection

Troubleshooting

Reference Documentation

Update History

Version

Date

Release Notes

0.0.1

01/2025

Initial version