Concepts First
- Audio player: implemented on the SDK's media service framework (MSP); supports local files, HTTP online audio, and Bluetooth A2DP sources.
- ROMFS: a read-only filesystem in Flash; the example packages demo music into ROMFS (mounted at
0x778000) and accesses it viafile:///romfs/.... - URL playback:
smta play <url>acceptsfile://(local) andhttp(s)://(network); the player decodes the format (MP3, etc.) automatically. - Volume API:
smta vol + / - / ?adjusts volume, implemented viasmtaudio_vol_up/down/get.
Example Overview
This page is based on the player example in the official Bouffalo SDK (examples/audio/player), which demonstrates audio playback on Ai-M6x:
- Initializes shell, Wi-Fi, MTD/EasyFlash, ROMFS, and the player (
app_player_init); - Plays local ROMFS audio or HTTP online audio via the
smta playshell command; - Supports stop/pause/resume (
smta stop|pause|resume) and volume control (smta vol); - The example family also includes Bluetooth audio (
player_bt/player_bt_only) and network audio (player_wifi) variants. - Sibling examples (
examples/audio/):player_mp3(simplified MP3),player_bt(Bluetooth audio),player_wifi(network audio),player_es8388(external ES8388 codec),codec(codec direct test).
Note
The player example is verified on BL616/BL618. Hardware needs a speaker/headphone plus PA circuit; confirm the audio output pins match your board. Simultaneous Wi-Fi and Bluetooth playback may be problematic in the current version — the README advises avoiding it.
Operation Steps
This page needs a board with a speaker/headphone interface. Open a terminal and enter the SDK audio player example directory (prerequisite: set up the environment as in Quick Start (Linux) or Windows):
cd examples/audio/playerRun the build command. The Ai-M62 (BL616) and Ai-M61 (BL618) belong to the same series, so both use bl616:
make CHIP=bl616 BOARD=bl616dkConnect the board with a USB cable, hold the BOOT button (IO2 on the Ai-M61-32S-Kit), briefly press EN/RST to enter download mode, then flash (replace the serial port with the one on your computer):
make flash CHIP=bl616 COMX=/dev/ttyUSB0Open a serial tool (baud rate 2000000). The example bundles a ROMFS audio file; at the bouffalolab /> prompt type:
smta play file:///romfs/music.mp3Connect to Wi-Fi first, then play an HTTP audio URL (HTTPS is supported):
wifi_sta_connect <SSID> <password>
smta play http://iot-du-home-test.bj.bcebos.com/test/bp_32k_mono_32kbps_03m53s.mp3Stop/pause/resume: smta stop, smta pause, smta resume; volume: smta vol +, smta vol -, smta vol ? (query).
Code Execution Flow
The complete flow from startup to audio playback is shown below:
APIs Used by the Example
smta(play url / stop / pause / resume / vol ...)
The player shell command: smta play <url> plays, smta stop|pause|resume controls state, smta vol +|-|?|[0-100] adjusts volume. Implemented and registered in app/player/cli_player.c.
Parameters: depends on the subcommand
Return: none
app_player_init()
Initializes the player (the playback component of the MSP media framework); must be called before playing.
Parameters: none
Return: none
smtaudio_start(media, url, seek_time, ...)
Starts playback of a URL on a media channel (MEDIA_SYSTEM system sound / MEDIA_MUSIC music).
Parameters:
media: media type (MEDIA_SYSTEM/MEDIA_MUSIC)url: playback address (file://orhttp(s)://)seek_time: seek offset in seconds
Return: playback status/error code
smtaudio_vol_up / smtaudio_vol_down / smtaudio_vol_get(step / step / )
Volume up/down/query. smtaudio_vol_get() returns the current volume (0-100).
Parameters:
step: adjustment step (e.g. 10)
Return: vol_get returns the current volume
romfs_mount(addr)
Mounts the ROMFS filesystem; the example mounts at 0x778000 so file:///romfs/... audio becomes accessible.
Parameters:
addr: Flash address of the ROMFS image
Return: 0 on success
Complete Code
The player entry sources below (main.c and app/app_main.c) match the official example (examples/audio/player) verbatim. Collapsed by default, click to expand:
📜 Click to expand player/main.c full code
/*
* Copyright (C) 2017-2022 Bouffalolab Group Holding Limited
* Change Logs:
* Date Author Notes
* 2019-03-25 MSP the first version
*/
#include "shell.h"
#include <FreeRTOS.h>
#include "task.h"
#include "board.h"
#define APP_MAIN_STACK_SIZE (4*1024)
#define APP_MAIN_TASK_PRIORITY (1)
static struct bflb_device_s *uart0;
extern void shell_init_with_task(struct bflb_device_s *shell);
extern void app_main_entry(void *arg);
int main(void)
{
TaskHandle_t xHandle;
board_init();
// configASSERT((configMAX_PRIORITIES > 4));
uart0 = bflb_device_get_by_name("uart0");
shell_init_with_task(uart0);
xTaskCreate(app_main_entry, (char *)"app_main", APP_MAIN_STACK_SIZE, NULL, APP_MAIN_TASK_PRIORITY, &xHandle);
vTaskStartScheduler();
while (1) {
}
}📜 Click to expand player/app/app_main.c full code
/*
* Copyright (C) 2017-2022 Bouffalolab Group Holding Limited
* Change Logs:
* Date Author Notes
* 2019-03-25 MSP the first version
*/
#include <FreeRTOS.h>
#include "task.h"
#include <app_wifi.h>
#if defined(CONFIG_BLUETOOTH)
#include <app_bt.h>
#endif
#include <app_player.h>
#include "rfparam_adapter.h"
#include "bflb_mtd.h"
#include "easyflash.h"
#include "bflb_romfs.h"
#include <sys/time.h>
#include <reent.h>
extern int _gettimeofday_r(struct _reent *, struct timeval *, void *);
int gettimeofday(struct timeval *tv, void *tz)
{
return _gettimeofday_r(_REENT, tv, tz);
}
void app_main_entry(void *arg)
{
/* Set ble controller EM Size */
#if defined(CONFIG_BLUETOOTH)
extern int bl_sys_em_config(void);
bl_sys_em_config();
#endif
/* Init rf */
if (0 != rfparam_init(0, NULL, 0)) {
printf("PHY RF init failed!\r\n");
return;
}
/* For bt status save */
bflb_mtd_init();
easyflash_init();
/* romsfs init mount use media factory*/
romfs_mount(0x778000);
// filesystem_init();
/* Init wifi */
app_wifi_init();
/* Init player */
app_player_init();
/* Init bt */
#if CONFIG_BLUETOOTH
app_bt_init();
#endif
#if defined(CONFIG_CODEC_USE_I2S)
extern msp_i2s_port_init(void);
msp_i2s_port_init();
#endif
extern int app_play_fifo_music();
app_play_fifo_music();
vTaskDelete(NULL);
}FAQ
No sound
Confirm the board has a speaker/headphone connected and the PA enable pin config is correct (g_pa_delay_2 and CONFIG_AUDIO_PA_PIN in multimedia_port.c); after running the play command, check the serial log for decode/playback messages.
Network audio does not play
First confirm Wi-Fi is connected with an IP (GOT_IP after wifi_sta_connect), then confirm the URL is reachable and the server supports HTTPS (the README sample link is HTTPS). When the network is unstable, test local ROMFS audio first.
Volume commands do nothing
Run smta play at least once first (cmd_player_func calls app_player_init()); after that, smta vol + / - / ? takes effect.
Have questions?
For any other questions, visit the unified Q&A and discussion board: Ai-Thinker Discussions

