### Register project components with CMake Source: https://github.com/snijderc/dyplayer/blob/main/examples/CMakeLists.txt Uses globbing to include all files in the examples directory as project sources. ```cmake # This file was automatically generated for projects # without default 'CMakeLists.txt' file. FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/examples/*.*) idf_component_register(SRCS ${app_sources}) ``` -------------------------------- ### POST /DYPlayer/previousDir Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Selects the previous directory and starts playing either the first or last song. ```APIDOC ## POST /DYPlayer/previousDir ### Description Select previous directory and start playing the first or last song. ### Method POST ### Endpoint DY::DYPlayer::previousDir(song) ### Parameters #### Request Body - **song** (playDirSound_t) - Required - Play DY::PreviousDir::FirstSound or DY::PreviousDir::LastSound ``` -------------------------------- ### select Source: https://context7.com/snijderc/dyplayer/llms.txt Select a sound file by number without starting playback. ```APIDOC ## select ### Description Select a sound file by number without starting playback. Useful for preparing tracks before playing. ### Parameters - **trackNumber** (uint16_t) - Required - The index of the track to select. ``` -------------------------------- ### Loading Sound Files by Path Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Example of how to specify sound files using paths and filenames. Directory and filename lengths are limited, and root files are prefixed with '/'. ```text /00001.MP3 ``` -------------------------------- ### Arduino HAL Implementation Source: https://github.com/snijderc/dyplayer/blob/main/README.MD A simplified example of extending DYPlayer for Arduino hardware. This implementation uses HardwareSerial for communication. ```C++ // player.hpp #include #include "DYPlayer.h" namespace DY { class Player: public DYPlayer { public: HardwareSerial *port; Player(); Player(HardwareSerial* port); void begin(); void serialWrite(uint8_t *buffer, uint8_t len); bool serialRead(uint8_t *buffer, uint8_t len); }; } //player.cpp #include "player.hpp" #include "DYPlayerArduino.h" namespace DY { Player::Player() { this->port = &Serial; } Player::Player(HardwareSerial* port) { this->port = port; } void Player::begin() { port->begin(9600); } void Player::serialWrite(uint8_t *buffer, uint8_t len) { port->write(buffer, len); } bool Player::serialRead(uint8_t *buffer, uint8_t len) { // Serial.setTimeout(1000); // Default timeout 1000ms. if(port->readBytes(buffer, len) > 0) { return true; } return false; } } ``` -------------------------------- ### GET /DYPlayer/getFirstInDir Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Retrieves the number of the first song in the currently selected directory. ```APIDOC ## GET /DYPlayer/getFirstInDir ### Description Get number of the first song in the currently selected directory. ### Method GET ### Endpoint DY::DYPlayer::getFirstInDir() ### Response #### Success Response (200) - **return** (uint16_t) - number of the first song in the currently selected directory ``` -------------------------------- ### ESP-IDF DYPlayer Initialization Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Initialize the DYPlayer on ESP-IDF using a specified UART number and custom TX/RX pins. This allows flexible serial communication setup. ```c++ DY::Player player(UART_NUM_2, 18, 19); ``` -------------------------------- ### Storage Device Control API Source: https://context7.com/snijderc/dyplayer/llms.txt Get or set the active storage device. ```APIDOC ## getPlayingDevice, setPlayingDevice ### Description Get or set the active storage device (USB, SD card, or onboard flash). ### Parameters #### Request Body - **device** (DY::device_t) - Required for setPlayingDevice - The target storage device. ``` -------------------------------- ### GET /DYPlayer/getPlayingSound Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Retrieves the number of the file currently being played. ```APIDOC ## GET /DYPlayer/getPlayingSound ### Description Get the currently playing file by number. ### Method GET ### Endpoint DY::DYPlayer::getPlayingSound() ### Response #### Success Response (200) - **return** (uint16_t) - number of the file currently playing ``` -------------------------------- ### GET /DYPlayer/getSoundCountDir Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Retrieves the total number of sound files in the currently selected directory, excluding subdirectories. ```APIDOC ## GET /DYPlayer/getSoundCountDir ### Description Get the amount of sound files in the currently selected directory. NOTE: Excluding files in sub directories. ### Method GET ### Endpoint DY::DYPlayer::getSoundCountDir() ### Response #### Success Response (200) - **return** (uint16_t) - number of sound files in currently selected directory ``` -------------------------------- ### Get Track Information Source: https://context7.com/snijderc/dyplayer/llms.txt Retrieve the currently playing track number and the total count of sound files available on the storage device. ```cpp #include #include "DYPlayerArduino.h" #include SoftwareSerial SoftSerial(10, 11); DY::Player player(&SoftSerial); void setup() { player.begin(); Serial.begin(9600); player.setVolume(15); player.setCycleMode(DY::PlayMode::Repeat); player.play(); } void loop() { uint16_t totalSounds = player.getSoundCount(); uint16_t currentSound = player.getPlayingSound(); Serial.print("Playing track "); Serial.print(currentSound); Serial.print(" of "); Serial.println(totalSounds); delay(500); } ``` -------------------------------- ### Control Storage Device Source: https://context7.com/snijderc/dyplayer/llms.txt Get or set the active storage device, which can be USB, SD card, or onboard flash. Handles cases for no device or communication failure. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); Serial.begin(9600); player.setVolume(15); // Available devices: // DY::Device::Usb - USB storage // DY::Device::Sd - SD card // DY::Device::Flash - Onboard flash chip // DY::Device::NoDevice - No device connected // DY::Device::Fail - Communication failure // Check current device DY::device_t currentDevice = player.getPlayingDevice(); if (currentDevice == DY::Device::Flash) { Serial.println("Using onboard flash"); } else if (currentDevice == DY::Device::Sd) { Serial.println("Using SD card"); } // Switch to SD card player.setPlayingDevice(DY::Device::Sd); } void loop() { player.playSpecified(1); delay(5000); } ``` -------------------------------- ### combinationPlay Source: https://context7.com/snijderc/dyplayer/llms.txt Create a playlist of multiple sound files for sequential playback. ```APIDOC ## combinationPlay ### Description Create a playlist of multiple sound files for sequential playback. Useful for combining audio samples. ### Parameters - **sounds** (char*[]) - Required - Array of sound file names (e.g., "01", "02"). - **count** (uint8_t) - Required - Number of files in the array. ``` -------------------------------- ### Initialize DY Player (ESP-IDF) Source: https://context7.com/snijderc/dyplayer/llms.txt Initializes the DY Player library for ESP32 using the ESP-IDF framework. Configurable UART port and GPIO pins are supported. ```cpp #include #include #include #include #include "DYPlayerESP32.h" #define TAG "dyplayer" // Initialize on UART2 with TX on GPIO 18, RX on GPIO 19 DY::Player player(UART_NUM_2, 18, 19); extern "C" void app_main(void) { vTaskDelay(1000 / portTICK_PERIOD_MS); // Allow module to initialize player.setVolume(15); ESP_LOGI(TAG, "Sound count: %u", (uint8_t)player.getSoundCount()); } ``` -------------------------------- ### Arduino DYPlayer Initialization Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Initialize the DYPlayer with a specific Serial port on Arduino. Ensure the correct Serial port is passed to the begin() function. ```c++ DY::Player player(&Serial2); ``` -------------------------------- ### File Selection Methods Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Methods for playing specific files by number or by device path. ```APIDOC ## POST /DYPlayer/playSpecified ### Description Play a sound file by number. ### Parameters #### Request Body - **number** (uint16_t) - Required - Number of the file (e.g., 1 for 00001.mp3) ## POST /DYPlayer/playSpecifiedDevicePath ### Description Play a sound file by device and path. ### Parameters #### Request Body - **device** (DY::device_t) - Required - The storage device (e.g., Flash or Sd) - **path** (char) - Required - Absolute path to the file ``` -------------------------------- ### Directory Navigation and Querying Source: https://context7.com/snijderc/dyplayer/llms.txt Retrieves directory metadata and navigates between folders to manage audio file organization. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); Serial.begin(9600); player.setVolume(15); } void loop() { // Get info about current directory uint16_t firstInDir = player.getFirstInDir(); uint16_t countInDir = player.getSoundCountDir(); Serial.print("Directory has "); Serial.print(countInDir); Serial.print(" files, starting at index "); Serial.println(firstInDir); // Navigate to previous directory and play first sound player.previousDir(DY::PreviousDir::FirstSound); delay(5000); // Or navigate and play last sound in directory player.previousDir(DY::PreviousDir::LastSound); delay(5000); } ``` -------------------------------- ### DYPlayer Control Methods Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Methods for configuring playback modes, equalizer settings, and file selection. ```APIDOC ## void DY::DYPlayer::setCycleMode(play_mode_t mode) ### Description Sets the cycle mode for the player. ### Parameters #### Path Parameters - **mode** (play_mode_t) - Required - The cycle mode to set. ## void DY::DYPlayer::setCycleTimes(uint16_t cycles) ### Description Set how many cycles to play when in repeat modes (0, 1, or 4). ### Parameters #### Path Parameters - **cycles** (uint16_t) - Required - The cycle count for repeat modes. ## void DY::DYPlayer::setEq(eq_t eq) ### Description Set the equalizer setting. ### Parameters #### Path Parameters - **eq** (eq_t) - Required - The equalizer setting. ## void DY::DYPlayer::select(uint16_t number) ### Description Select a sound file without playing it. ### Parameters #### Path Parameters - **number** (uint16_t) - Required - The number of the file, e.g., 1 for 00001.mp3. ## void DY::DYPlayer::combinationPlay(char* sounds, uint8_t len) ### Description Allows you to make a playlist of multiple sound files to play in sequence. ### Parameters #### Path Parameters - **sounds** (char) - Required - An array of char[2] containing the names of sounds to play in order. - **len** (uint8_t) - Required - The length of the passed array. ## void DY::DYPlayer::endCombinationPlay() ### Description End combination play mode. ``` -------------------------------- ### Initialize DY Player (Arduino) Source: https://context7.com/snijderc/dyplayer/llms.txt Initializes the DY Player library for Arduino. Can use the default Serial port, a specific HardwareSerial port, or a SoftwareSerial port. ```cpp #include #include "DYPlayerArduino.h" // Default initialization using Serial DY::Player player; // Or use a specific hardware serial port // DY::Player player(&Serial2); // Or use SoftwareSerial on custom pins // #include // SoftwareSerial SoftSerial(10, 11); // RX, TX // DY::Player player(&SoftSerial); void setup() { player.begin(); // Initialize serial communication at 9600 baud player.setVolume(15); // Set initial volume (0-30, default is 20) } ``` -------------------------------- ### POST /DYPlayer/interludeSpecifiedDevicePath Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Plays an interlude file specified by device and absolute path. ```APIDOC ## POST /DYPlayer/interludeSpecifiedDevicePath ### Description Play an interlude by device and path. ### Method POST ### Endpoint DY::DYPlayer::interludeSpecifiedDevicePath(device, path) ### Parameters #### Request Body - **device** (DY::device_t) - Required - A DY::Device member e.g DY::Device::Flash or DY::Device::Sd - **path** (char) - Required - pointer to the path of the file (asbsolute) ``` -------------------------------- ### Sound File Naming Convention Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Recommended naming convention for sound files to ensure sequential playback. Files should be zero-padded and sequentially numbered. ```text 00001.mp3 00002.mp3 00003.mp3 ... 65535.mp3 ``` -------------------------------- ### DYPlayer Enumerations Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Definitions for storage devices, play states, and equalizer settings. ```APIDOC ## enum class DY::device_t ### Description Storage devices reported by the module. - **DY::Device::Usb** (0x00) - USB Storage device. - **DY::Device::Sd** (0x01) - SD Card. - **DY::Device::Flash** (0x02) - Onboard flash chip. - **DY::Device::Fail** (0xfe) - UART failure. - **DY::Device::NoDevice** (0xff) - No storage device is online. ## enum class DY::play_state_t ### Description The current module play state. - **DY::PlayState::Fail** (-1) - UART Failure. - **DY::PlayState::Stopped** (0) - Stopped. - **DY::PlayState::Playing** (1) - Playing. - **DY::PlayState::Paused** (2) - Paused. ## enum class DY::eq_t ### Description Equalizer settings. - **DY::Eq::Normal** (0x00) - **DY::Eq::Pop** (0x01) - **DY::Eq::Rock** (0x02) - **DY::Eq::Jazz** (0x03) - **DY::Eq::Classic** (0x04) ``` -------------------------------- ### Configure Equalizer Settings Source: https://context7.com/snijderc/dyplayer/llms.txt Set the equalizer preset to tailor audio profiles. Available options include Normal, Pop, Rock, Jazz, and Classic. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); player.setVolume(15); // Available EQ settings: // DY::Eq::Normal - Flat frequency response // DY::Eq::Pop - Enhanced vocals and mid-range // DY::Eq::Rock - Enhanced bass and treble // DY::Eq::Jazz - Warm mid-range // DY::Eq::Classic - Balanced classical profile player.setEq(DY::Eq::Rock); player.playSpecified(1); } void loop() { delay(10000); player.setEq(DY::Eq::Jazz); delay(10000); player.setEq(DY::Eq::Normal); } ``` -------------------------------- ### Play Sound by Path (Arduino) Source: https://context7.com/snijderc/dyplayer/llms.txt Plays a sound file by specifying the storage device and its absolute path. Paths support up to two nested directories with 8-character names. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); player.setVolume(15); } void loop() { // Play from onboard flash char flashPath[] = "/00001.MP3"; player.playSpecifiedDevicePath(DY::Device::Flash, flashPath); delay(5000); // Play from SD card with nested directory char sdPath[] = "/SOUNDS/ALERTS/BEEP.MP3"; player.playSpecifiedDevicePath(DY::Device::Sd, sdPath); delay(5000); } ``` -------------------------------- ### Combination Playback with DYPlayer Source: https://context7.com/snijderc/dyplayer/llms.txt Plays a sequence of audio files stored in /DY/, /XY/, or /ZH/ directories. Files must be named as 2-digit numbers. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); player.setVolume(10); } void loop() { // Files must be in /DY/, /XY/, or /ZH/ directory // Named as 2-digit numbers: 01.mp3, 02.mp3, etc. char *sounds[] = { "01", "02", "03" }; player.combinationPlay(sounds, 3); // Monitor playback progress uint16_t lastSound = 0; for (uint8_t i = 0; i < 200; i++) { uint16_t currentSound = player.getPlayingSound(); if (lastSound != currentSound) { lastSound = currentSound; i = 0; // Reset timeout counter } delay(50); } // End combination play mode player.endCombinationPlay(); delay(30000); } ``` -------------------------------- ### DYPlayer Methods Source: https://github.com/snijderc/dyplayer/blob/main/README.MD List of available methods for controlling the DYPlayer module. ```APIDOC ## Available Methods - **checkPlayState** (0x01) - Check the current play state. - **play** (0x02) - Start playback. - **pause** (0x03) - Pause playback. - **stop** (0x04) - Stop playback. - **previous** (0x05) - Play previous music. - **next** (0x06) - Play next music. - **playSpecified** (0x07) - Play a specific music file. - **playSpecifiedDevicePath** (0x08) - Play from a specific device and path. - **getPlayingDevice** (0x0a) - Check current playing device. - **setPlayingDevice** (0x0b) - Switch to a selected device. - **getSoundCount** (0x0c) - Check total number of music files. - **getPlayingSound** (0x0d) - Check current music index. - **previousDir** (0x0e/0x0f) - Navigate folder directories. - **stopInterlude** (0x10) - End interlude playing. - **getFirstInDir** (0x11) - Check first music in folder. - **getSoundCountDir** (0x12) - Check number of music in folder. - **setVolume** (0x13) - Set volume level. - **volumeIncrease** (0x14) - Increase volume. - **volumeDecrease** (0x15) - Decrease volume. - **interludeSpecified** (0x16) - Select file for interlude. - **interludeSpecifiedDevicePath** (0x17) - Select path for interlude. - **setCycleMode** (0x18) - Set cycle mode. - **setCycleTimes** (0x19) - Set cycle times. - **setEq** (0x1a) - Set EQ settings. - **combinationPlay** (0x1b) - Start combination play. - **endCombinationPlay** (0x1c) - End combination play. - **select** (0x1f) - Select file without playing. ``` -------------------------------- ### Playback Control Methods Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Methods for controlling the playback state and navigation of audio files. ```APIDOC ## GET /DYPlayer/checkPlayState ### Description Check the current play state of the player. ### Method GET ### Response #### Success Response (200) - **return** (DY::play_state_t) - Play status (e.g., Stopped, Playing) ## POST /DYPlayer/play ### Description Play the currently selected file from the start. ## POST /DYPlayer/pause ### Description Set the play state to paused. ## POST /DYPlayer/stop ### Description Set the play state to stopped. ## POST /DYPlayer/previous ### Description Play the previous file. ## POST /DYPlayer/next ### Description Play the next file. ``` -------------------------------- ### Play Sound by Number (Arduino) Source: https://context7.com/snijderc/dyplayer/llms.txt Plays a specific sound file by its index number. Sound files must be named sequentially (e.g., 00001.mp3) and stored in order. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); player.setVolume(15); } void loop() { player.playSpecified(1); // Play first sound file (00001.mp3) delay(5000); player.playSpecified(2); // Play second sound file (00002.mp3) delay(5000); } ``` -------------------------------- ### UART Command Structure Source: https://github.com/snijderc/dyplayer/blob/main/README.MD The general format for sending commands to the DYPlayer module. ```APIDOC ## UART Command Format ### Description All commands follow a specific byte-oriented structure to communicate with the DYPlayer hardware. ### Format `aa [cmd] [len] [byte_1..n] [crc]` ### Components - **aa**: Start byte - **[cmd]**: Command byte (e.g., 0x01 for check play state) - **[len]**: Length of the argument bytes - **[byte_1..n]**: Argument bytes - **[crc]**: CRC checksum byte ``` -------------------------------- ### Equalizer Settings API Source: https://context7.com/snijderc/dyplayer/llms.txt Configure the equalizer preset for different audio profiles. ```APIDOC ## setEq ### Description Configure the equalizer preset for different audio profiles. ### Parameters #### Request Body - **eq** (DY::Eq) - Required - The equalizer preset (Normal, Pop, Rock, Jazz, Classic). ``` -------------------------------- ### POST /DYPlayer/interludeSpecified Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Plays an interlude file specified by device and number. ```APIDOC ## POST /DYPlayer/interludeSpecified ### Description Play an interlude file by device and number, number sent as 2 bytes. ### Method POST ### Endpoint DY::DYPlayer::interludeSpecified(device, number) ### Parameters #### Request Body - **device** (DY::device_t) - Required - A DY::Device member e.g DY::Device::Flash or DY::Device::Sd - **number** (uint16_t) - Required - number of the file, e.g. 1 for 00001.mp3 ``` -------------------------------- ### Directory Navigation Source: https://context7.com/snijderc/dyplayer/llms.txt Navigate directories and query directory-level information. ```APIDOC ## Directory Navigation ### Description Methods to navigate directories and query information about files within them. ### Methods - **getFirstInDir()**: Returns the index of the first sound in the current directory. - **getSoundCountDir()**: Returns the total number of sounds in the current directory. - **previousDir(mode)**: Navigates to the previous directory. Mode can be FirstSound or LastSound. ``` -------------------------------- ### Perform Combination Play Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Plays a sequence of sound files specified by their two-digit names. Files must be stored in a specific directory (e.g., 'DY', 'ZH', or 'XY') and passed as an array of character pointers. ```cpp const char * sounds[2][3] = { "01", "02" }; DY::DYPlayer::combinationPlay(sounds, 2); ``` -------------------------------- ### Combination Playback Directory Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Specifies the directory format for combination playback. Files should have 2-character names plus extension, within a specific directory (e.g., 'DY' or 'XY'). ```text /DY/##.MP3 ``` -------------------------------- ### Device and Metadata Management Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Methods for managing storage devices and retrieving file information. ```APIDOC ## GET /DYPlayer/getPlayingDevice ### Description Get the storage device currently used for playing sound files. ### Response #### Success Response (200) - **return** (DY::device_t) - The current storage device ## POST /DYPlayer/setPlayingDevice ### Description Set the device number the module should use. ### Parameters #### Request Body - **device** (DY::device_t) - Required - The storage device to set ## GET /DYPlayer/getSoundCount ### Description Get the amount of sound files on the current storage device. ### Response #### Success Response (200) - **return** (uint16_t) - Number of sound files ``` -------------------------------- ### POST /DYPlayer/setVolume Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Sets the playback volume to a value between 0 and 30. ```APIDOC ## POST /DYPlayer/setVolume ### Description Set the playback volume between 0 and 30. Default volume if not set: 20. ### Method POST ### Endpoint DY::DYPlayer::setVolume(volume) ### Parameters #### Request Body - **volume** (uint8_t) - Required - volume to set (0-30) ``` -------------------------------- ### Playback State API Source: https://context7.com/snijderc/dyplayer/llms.txt Query the module for current playback state. ```APIDOC ## checkPlayState ### Description Query the module for current playback state (stopped, playing, paused, or communication failure). ### Response #### Success Response (200) - **state** (DY::play_state_t) - The current playback state. ``` -------------------------------- ### POST /DYPlayer/volumeIncrease Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Increases the playback volume. ```APIDOC ## POST /DYPlayer/volumeIncrease ### Description Increase the volume. ### Method POST ### Endpoint DY::DYPlayer::volumeIncrease() ``` -------------------------------- ### setCycleTimes Source: https://context7.com/snijderc/dyplayer/llms.txt Configure how many times to repeat playback. ```APIDOC ## setCycleTimes ### Description Configure how many times to repeat playback when using repeat modes (Repeat, RepeatOne, RepeatDir). ### Parameters - **times** (uint16_t) - Required - Number of times to repeat. ``` -------------------------------- ### Check Playback State Source: https://context7.com/snijderc/dyplayer/llms.txt Query the module to determine the current playback status, such as Stopped, Playing, Paused, or if a communication failure has occurred. ```cpp #include #include "DYPlayerArduino.h" #include SoftwareSerial SoftSerial(10, 11); DY::Player player(&SoftSerial); void setup() { player.begin(); Serial.begin(9600); // Debug output on hardware serial player.setVolume(15); player.playSpecified(1); } void loop() { DY::play_state_t state = player.checkPlayState(); switch (state) { case DY::PlayState::Stopped: Serial.println("Status: Stopped"); break; case DY::PlayState::Playing: Serial.println("Status: Playing"); break; case DY::PlayState::Paused: Serial.println("Status: Paused"); break; case DY::PlayState::Fail: Serial.println("Status: Communication failure"); break; } delay(1000); } ``` -------------------------------- ### Playback Control (Arduino) Source: https://context7.com/snijderc/dyplayer/llms.txt Controls playback state using methods to play, pause, stop, skip to the next track, or go back to the previous track. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); player.setVolume(20); player.playSpecified(1); // Start playing first track } void loop() { delay(3000); player.pause(); // Pause playback delay(2000); player.play(); // Resume playback from pause delay(3000); player.next(); // Skip to next track delay(3000); player.previous(); // Go back to previous track delay(3000); player.stop(); // Stop playback completely delay(5000); player.play(); // Start playing from beginning } ``` -------------------------------- ### Custom Hardware Abstraction Layer Implementation Source: https://context7.com/snijderc/dyplayer/llms.txt Extends the DYPlayer base class to implement serial communication for non-Arduino platforms. ```cpp #include "DYPlayer.h" namespace DY { class CustomPlayer : public DYPlayer { public: // Your serial port handle void* serialPort; CustomPlayer(void* port) { this->serialPort = port; } // Initialize serial at 9600 baud void begin() { // Platform-specific serial initialization // Configure: 9600 baud, 8N1 } // Required: Write bytes to serial port void serialWrite(uint8_t *buffer, uint8_t len) override { // Platform-specific write implementation // Example: uart_write(serialPort, buffer, len); } // Required: Read bytes from serial port with timeout bool serialRead(uint8_t *buffer, uint8_t len) override { // Platform-specific read implementation // Must return true if all bytes read successfully // Must return false on timeout or error // Default timeout should be ~1000ms // Example: // int bytesRead = uart_read_timeout(serialPort, buffer, len, 1000); // return (bytesRead == len); return false; } }; } ``` -------------------------------- ### Set Playback Mode (Arduino) Source: https://context7.com/snijderc/dyplayer/llms.txt Configures the playback cycle mode, including repeat, shuffle, sequence, and single-track modes. Use DY::PlayMode enum for settings. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); player.setVolume(15); // Available play modes: // DY::PlayMode::Repeat - Play all in sequence, repeat forever // DY::PlayMode::RepeatOne - Repeat current track // DY::PlayMode::OneOff - Play once and stop (default) // DY::PlayMode::Random - Shuffle all tracks, repeat // DY::PlayMode::RepeatDir - Repeat current directory // DY::PlayMode::RandomDir - Shuffle current directory // DY::PlayMode::SequenceDir - Play directory in sequence, stop // DY::PlayMode::Sequence - Play all in sequence, stop player.setCycleMode(DY::PlayMode::Repeat); // Play all and repeat player.play(); } void loop() { delay(5000); } ``` -------------------------------- ### Select Track Without Playing Source: https://context7.com/snijderc/dyplayer/llms.txt Pre-selects a track index to prepare it for playback without triggering audio output immediately. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); player.setVolume(15); // Pre-select track 5 without playing player.select(5); } void loop() { // Wait for button press or other trigger delay(5000); // Now play the pre-selected track player.play(); delay(10000); // Select and prepare next track player.select(6); } ``` -------------------------------- ### Volume Control API Source: https://context7.com/snijderc/dyplayer/llms.txt Methods to set absolute volume or perform relative adjustments. ```APIDOC ## setVolume, volumeIncrease, volumeDecrease ### Description Control playback volume with absolute value or relative adjustments. Volume range is 0-30, default is 20. ### Parameters #### Request Body - **volume** (uint8_t) - Required for setVolume - The target volume level (0-30). ``` -------------------------------- ### Track Information API Source: https://context7.com/snijderc/dyplayer/llms.txt Query the currently playing track number and total sound file count. ```APIDOC ## getPlayingSound, getSoundCount ### Description Query the currently playing track number and total sound file count on the storage device. ### Response #### Success Response (200) - **currentSound** (uint16_t) - The index of the currently playing track. - **totalSounds** (uint16_t) - The total number of sound files available. ``` -------------------------------- ### Set and Adjust Volume Source: https://context7.com/snijderc/dyplayer/llms.txt Control playback volume using absolute values or relative increments/decrements. The volume ranges from 0 to 30. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); player.setVolume(15); // Set to 50% volume (15 out of 30) player.playSpecified(1); } void loop() { delay(2000); player.volumeIncrease(); // Increase volume by 1 step delay(2000); player.volumeIncrease(); delay(2000); player.volumeDecrease(); // Decrease volume by 1 step delay(2000); player.setVolume(5); // Set to low volume delay(2000); player.setVolume(25); // Set to high volume } ``` -------------------------------- ### POST /DYPlayer/stopInterlude Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Stops the current interlude and resumes normal playback. ```APIDOC ## POST /DYPlayer/stopInterlude ### Description Stop the interlude and continue playing. Will also stop the current sound from playing if interlude is not active. ### Method POST ### Endpoint DY::DYPlayer::stopInterlude() ``` -------------------------------- ### POST /DYPlayer/volumeDecrease Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Decreases the playback volume. ```APIDOC ## POST /DYPlayer/volumeDecrease ### Description Decrease the volume. ### Method POST ### Endpoint DY::DYPlayer::volumeDecrease() ``` -------------------------------- ### Interlude Playback API Source: https://context7.com/snijderc/dyplayer/llms.txt Play an interlude sound that interrupts current playback. ```APIDOC ## interludeSpecified, stopInterlude ### Description Play an interlude sound that interrupts current playback, then resumes from the breakpoint. ### Parameters #### Request Body - **device** (DY::Device) - Required - The storage device containing the interlude. - **track** (uint16_t) - Required - The track index to play as an interlude. ``` -------------------------------- ### Play Interlude Sound Source: https://context7.com/snijderc/dyplayer/llms.txt Interrupt current playback to play a short interlude sound, then resume the main audio from where it was paused. Supports specifying device and path. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); player.setVolume(15); player.setCycleMode(DY::PlayMode::Repeat); player.play(); // Start background music } void loop() { delay(10000); // Play notification sound as interlude from flash // Music will pause, notification plays, then music resumes player.interludeSpecified(DY::Device::Flash, 5); delay(15000); // Or use path-based interlude char alertPath[] = "/ALERTS/DING.MP3"; player.interludeSpecifiedDevicePath(DY::Device::Flash, alertPath); delay(10000); // Manually stop interlude and resume main playback player.stopInterlude(); } ``` -------------------------------- ### DYPlayer Play Modes Enum Source: https://github.com/snijderc/dyplayer/blob/main/README.MD Defines the available playback modes for the DYPlayer library. Use these to control how sound files are played. ```cpp typedef enum class DY::play_mode_t ``` -------------------------------- ### Set Repeat Cycle Count Source: https://context7.com/snijderc/dyplayer/llms.txt Configures the number of times a track repeats when using Repeat, RepeatOne, or RepeatDir modes. ```cpp #include #include "DYPlayerArduino.h" DY::Player player; void setup() { player.begin(); player.setVolume(15); // Set to repeat current track mode player.setCycleMode(DY::PlayMode::RepeatOne); // Repeat the track 3 times then stop player.setCycleTimes(3); player.playSpecified(1); } void loop() { delay(5000); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.