Skip to content

Commit

Permalink
feat(mp3_demo): add usb audio player based on usb_host_uac
Browse files Browse the repository at this point in the history
Co-authored-by: Li Bo <[email protected]>
  • Loading branch information
liangshuzhi5193 and leeebo committed Jul 11, 2024
1 parent 14662c9 commit 68b3514
Show file tree
Hide file tree
Showing 12 changed files with 425 additions and 33 deletions.
20 changes: 18 additions & 2 deletions examples/mp3_demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
| ESP32-S3-BOX-Lite | YES |
| ESP32-S3-BOX-3 | YES |

Play MP3 music on ESP-BOX.
Playing MP3 music on the ESP-BOX supports external USB headphone playback (only compatible with **ESP32-S3-BOX-3**) and playback through the built-in speakers of the ESP-BOX.

When USB headphones are connected, the example defaults to playing through the USB headphones. When the headphones are disconnected, it automatically switches to speaker playback. When the headphones are reconnected, it switches back to headphone playback.


> **Note:** Playing music through USB headphones requires the USB port to **support power output**. However, the USB Type-C port on the left side of the ESP-BOX does not provide power output. Therefore, You need to connect it to the **ESP32-S3-BOX-3-DOCK** base and use a **USB-A to Type-C adapter** (or a **USB-A to 3.5mm headphone jack adapter**) for operation, as shown in the diagram below.
<div align="center">
<img src="https://dl.espressif.com/ae/esp-box/box_mp3_demo.png/box_mp3_demo.png" width="60%">
</div>

This demo will scan the files in the specified directory (`/spiffs` by default) and try to decode and play. You can manually mount the SD card and switch to play MP3 files from the SD card.

Expand All @@ -16,8 +25,10 @@ We will support switching the sample rate and the number of channels in the next

### Hardware Required

* A ESP32-S3-Box or ESP32-S3-BOX-Lite
* A ESP32-S3-BOX-3 / ESP32-S3-Box / ESP32-S3-BOX-Lite
* A USB-C cable for power supply and programming
* ESP32-S3-BOX-3-DOCK
* a USB headphones or USB-A to 3.5-mm headphone jack adapter

Follow detailed instructions provided specifically for this example.

Expand All @@ -29,3 +40,8 @@ Once a complete flash process has been performed, you can use `idf.py app-flash

(To exit the serial monitor, type `Ctrl-]`. Please reset the development board f you cannot exit the monitor.)

### Demo Display

<div align="center">
<img src="https://dl.espressif.com/ae/esp-box/box_mp3_demo.gif/box_mp3_demo.gif" width="60%">
</div>
5 changes: 3 additions & 2 deletions examples/mp3_demo/main/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
dependencies:
idf: ">=5.0"

chmorgan/esp-audio-player: "1.0.5"
chmorgan/esp-file-iterator: "1.0.0"
chmorgan/esp-audio-player: "1.0.*"
chmorgan/esp-file-iterator: "1.0.0"
usb_host_uac: "1.0.*"
8 changes: 7 additions & 1 deletion examples/mp3_demo/main/include/ui_audio.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
Expand All @@ -24,6 +24,12 @@ void ui_audio_start(file_iterator_instance_t *i);
*/
uint8_t get_sys_volume();

/**
* @brief get current music index
*
*/
uint8_t get_current_music_index();

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 68b3514

Please sign in to comment.