Playlist

[中文]

A playlist is a list of audio files that can be played back either sequentially or in a specified order.

The sdcard_scan() function in the playlist/include/sdcard_scan.h scans the audio files in a microSD card and generate a playlist of files. You can specify file depth and filter out file types when scanning. The playlist instances can be saved to a variety of storage media. The following are the supported storage media:

After scanning the audio files, you can use the playlist_operator_handle_t handle to call the corresponding functions to create, save, print playlists, and obtain the path corresponding to the audio ID. Currently, most of the storage media mentioned in this document support the above functions.

See the description below for the API details.

Scanning MicroSD Card

The sdcard_scan() function can scan audio files in a specified path and generate playlists. It supports the scanning of files at a specified depth and filtering of file types. Then, the playlist can be saved to the specified storage medium using a callback function.

Application Example

Header File

Functions

esp_err_t sdcard_scan(sdcard_scan_cb_t cb, const char *path, int depth, const char *file_extension[], int filter_num, void *user_data)

Scan files in SD card and use callback function to save files that meet filtering conditions.

Note

example sdcard_scan(callback, “/sdcard”, 5, const char *[]{“mp3”, “aac”}, 2, user_data); Scan 5 levels folder in sdcard and save mp3 files and aac files.

Parameters
  • cb – The callback function

  • path – The path to be scanned

  • depth – The depth of file scanning // .e.g. if you only want to save files in “/test” , depth = 0. // if you want to save files in “/test/scan_test/”, depth = 1

  • file_extension – File extension of files that are supposed to be saved // .e.g. const char *[]{“mp3”, “aac”}

  • filter_num – Number of filters

  • user_data – The data to be used by callback function

Returns

  • ESP_OK success

  • ESP_FAIL failed

Type Definitions

typedef void (*sdcard_scan_cb_t)(void *user_data, char *url)

Saving Playlist

Saving to MicroSD Card

The playlist can be stored in the microSD card. Functions, such as those to save and display the playlist, can be called through the playlist_operator_handle_t handle.

Application Example

Header File

Functions

esp_err_t sdcard_list_create(playlist_operator_handle_t *handle)

Create a playlist in sdcard by list id.

Parameters

handle[out] The playlist handle from application layer

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t sdcard_list_show(playlist_operator_handle_t handle)

Show all the URLs in sdcard playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t sdcard_list_next(playlist_operator_handle_t handle, int step, char **url_buff)

The following URLs in sdcard playlist.

Parameters
  • handle – Playlist handle

  • step – The offset of URL from current URL

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t sdcard_list_prev(playlist_operator_handle_t handle, int step, char **url_buff)

The previous URLs in sdcard playlist.

Parameters
  • handle – Playlist handle

  • step – The offset of URL from current URL

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

bool sdcard_list_exist(playlist_operator_handle_t handle, const char *url)

Judge whether the url exists in sdcard playlist.

Parameters
  • handle – Playlist handle

  • url – The url to be checked

Returns

  • true existence

  • false Non-existent

esp_err_t sdcard_list_reset(playlist_operator_handle_t handle)

Reset sdcard playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t sdcard_list_current(playlist_operator_handle_t handle, char **url_buff)

Get current URL in sdcard playlist.

Parameters
  • handle – Playlist handle

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t sdcard_list_choose(playlist_operator_handle_t handle, int url_id, char **url_buff)

Choose a url by url id.

Parameters
  • handle – Playlist handle

  • url_id – The id of url in sdcard list

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

int sdcard_list_get_url_num(playlist_operator_handle_t handle)

Get URLs number in sdcard playlist.

Parameters

handle – Playlist handle

Returns

  • URLs number in sdcard playlist

  • ESP_FAIL Fail to get number of urls

int sdcard_list_get_url_id(playlist_operator_handle_t handle)

Get current url id in the sdcard playlist.

Parameters

handle – Playlist handle

Returns

  • Current url id in partition playlist

  • ESP_FAIL Fail to get url id

esp_err_t sdcard_list_destroy(playlist_operator_handle_t handle)

Destroy sdcard playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t sdcard_list_save(playlist_operator_handle_t handle, const char *url)

Save URL to sdcard playlist.

Parameters
  • handle – Playlist handle

  • url – URL to be saved

Returns

  • ESP_OK success

  • ESP_FAIL failed

Saving to DRAM

The playlist can be stored in DRAM. Functions, such as those to save and display the playlist, can be called through the playlist_operator_handle_t handle.

Header File

Functions

esp_err_t dram_list_create(playlist_operator_handle_t *handle)

Create a playlist in dram.

Parameters

handle[out] The playlist handle from application layer

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t dram_list_save(playlist_operator_handle_t handle, const char *url)

Save URL to dram playlist.

Parameters
  • handle – Playlist handle

  • url – URL to be saved

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t dram_list_next(playlist_operator_handle_t handle, int step, char **url_buff)

The following URLs in dram playlist.

Parameters
  • handle – Playlist handle

  • step – The offset of URL from current URL

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t dram_list_prev(playlist_operator_handle_t handle, int step, char **url_buff)

The previous URLs in dram playlist.

Parameters
  • handle – Playlist handle

  • step – The offset of URL from current URL

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

bool dram_list_exist(playlist_operator_handle_t handle, const char *url)

Judge whether the url exists in dram playlist.

Parameters
  • handle – Playlist handle

  • url – The url to be checked

Returns

  • true existence

  • false Non-existent

esp_err_t dram_list_reset(playlist_operator_handle_t handle)

Reset dram playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t dram_list_current(playlist_operator_handle_t handle, char **url_buff)

The current URL in current playlist.

Parameters
  • handle – Playlist handle

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t dram_list_choose(playlist_operator_handle_t handle, int url_id, char **url_buff)

Choose a url by url id.

Parameters
  • handle – Playlist handle

  • url_id – The id of url in dram list

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

int dram_list_get_url_num(playlist_operator_handle_t handle)

Get URLs number in the dram playlist.

Parameters

handle – Playlist handle

Returns

  • URLs number in dram playlist

  • ESP_FAIL Fail to get number of urls

int dram_list_get_url_id(playlist_operator_handle_t handle)

Get current url id in the dram playlist.

Parameters

handle – Playlist handle

Returns

  • Current url id in dram playlist

  • ESP_FAIL Fail to get url id

esp_err_t dram_list_show(playlist_operator_handle_t handle)

Show all the URLs in the dram playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t dram_list_remove_by_url(playlist_operator_handle_t handle, const char *url)

Remove corrsponding url in dram list.

Parameters
  • handle – Playlist handle

  • url – The url to be removed

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t dram_list_remove_by_url_id(playlist_operator_handle_t handle, uint16_t url_id)

Remove url by id.

Parameters
  • handle – Playlist handle

  • url_id – The url id to be removed

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t dram_list_destroy(playlist_operator_handle_t handle)

Destroy the dram playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

Saving to NVS Partition in Flash

The playlist can be stored in the NVS partition in flash. Functions, such as those to save and display the playlist, can be called through the playlist_operator_handle_t handle.

Header File

Functions

esp_err_t flash_list_create(playlist_operator_handle_t *handle)

Create a playlist in nvs flash.

Parameters

handle[out] Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t flash_list_save(playlist_operator_handle_t handle, const char *url)

Save URL to nvs flash list.

Parameters
  • handle – Playlist handle

  • url – URL to be saved

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t flash_list_show(playlist_operator_handle_t handle)

Show all the URLs in nvs flash list.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t flash_list_next(playlist_operator_handle_t handle, int step, char **url_buff)

The following URLs in nvs flash playlist.

Parameters
  • handle – Playlist handle

  • step – The offset of URL from current URL

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t flash_list_prev(playlist_operator_handle_t handle, int step, char **url_buff)

The previous URLs in nvs flash playlist.

Parameters
  • handle – Playlist handle

  • step – The offset of URL from current URL

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t flash_list_current(playlist_operator_handle_t handle, char **url_buff)

The current URL in nvs flash playlist.

Parameters
  • handle – Playlist handle

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

bool flash_list_exist(playlist_operator_handle_t handle, const char *url)

Judge whether the url exists in flash playlist.

Parameters
  • handle – Playlist handle

  • url – The url to be checked

Returns

  • true existence

  • false Non-existent

esp_err_t flash_list_reset(playlist_operator_handle_t handle)

Reset flash playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t flash_list_choose(playlist_operator_handle_t handle, int url_id, char **url_buff)

Choose a url by url id.

Parameters
  • handle – Playlist handle

  • url_id – The id of url in flash list

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

int flash_list_get_url_num(playlist_operator_handle_t handle)

Get URLs number in the flash playlist.

Parameters

handle – Playlist handle

Returns

  • URLs number in flash playlist

  • ESP_FAIL Fail to get number of urls

int flash_list_get_url_id(playlist_operator_handle_t handle)

Get current url id in the flash playlist.

Parameters

handle – Playlist handle

Returns

  • Curernt url id in flash playlist

  • ESP_FAIL Fail to get url id

esp_err_t flash_list_destroy(playlist_operator_handle_t handle)

Destroy the nvs flash playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

Saving to DATA_UNDEFINED Partition in Flash

The playlist can be stored in the DATA_UNDEFINED partition (see Partition Tables for details) in flash. Functions, such as those to save and display the playlist, can be called through the playlist_operator_handle_t handle. Please add the two partitions whose subtypes are 0x06 and 0x07 to the flash partition table first.

Header File

Functions

esp_err_t partition_list_create(playlist_operator_handle_t *handle)

Create a playlist in flash partition by list id.

Note

Please add 2 partitions to partition table whose subtype are 0x06 and 0x07 first

Parameters

handle[out] The playlist handle from application layer

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t partition_list_save(playlist_operator_handle_t handle, const char *url)

Save URL to partition playlist.

Parameters
  • handle – Playlist handle

  • url – URL to be saved

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t partition_list_next(playlist_operator_handle_t handle, int step, char **url_buff)

The following URLs in partition playlist.

Parameters
  • handle – Playlist handle

  • step – The offset of URL from current URL

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t partition_list_prev(playlist_operator_handle_t handle, int step, char **url_buff)

The previous URLs in partition playlist.

Parameters
  • handle – Playlist handle

  • step – The offset of URL from current URL

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

bool partition_list_exist(playlist_operator_handle_t handle, const char *url)

Judge whether the url exists in partition playlist.

Parameters
  • handle – Playlist handle

  • url – The url to be checked

Returns

  • true existence

  • false Non-existent

esp_err_t partition_list_reset(playlist_operator_handle_t handle)

Reset partition playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t partition_list_current(playlist_operator_handle_t handle, char **url_buff)

Get current URL in the partition playlist.

Parameters
  • handle – Playlist handle

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t partition_list_choose(playlist_operator_handle_t handle, int url_id, char **url_buff)

Choose a url by url id.

Parameters
  • handle – Playlist handle

  • url_id – The id of url in partition list

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

int partition_list_get_url_num(playlist_operator_handle_t handle)

Get URLs number in the partition playlist.

Parameters

handle – Playlist handle

Returns

  • URLs number in partition playlist

  • ESP_FAIL Fail to get number of urls

int partition_list_get_url_id(playlist_operator_handle_t handle)

Get curernt url id in the partition playlist.

Parameters

handle – Playlist handle

Returns

  • Current url id in partition playlist

  • ESP_FAIL Fail to get url id

esp_err_t partition_list_show(playlist_operator_handle_t handle)

Show all the URLs in the partition playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t partition_list_destroy(playlist_operator_handle_t handle)

Destroy the partition playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

Playlist Manager

Playlist Manager manages the above playlists and can add multiple playlist instances to the playlist_handle_t handle.

Header File

Functions

playlist_handle_t playlist_create(void)

Create a playlist manager handle.

Returns

  • playlist handle success

  • NULL failed

esp_err_t playlist_add(playlist_handle_t handle, playlist_operator_handle_t list_handle, uint8_t list_id)

Create a playlist manager and add playlist handle to it.

Note

The partition playlist can only be added once, or it will be overwrited by the newest partiiton playlist

Note

Different lists must use different IDs, because even if they are in different handles, list_id is the only indicator that distinguishes them.

Parameters
  • handle – Playlist manager handle

  • list_handle – The playlist handle to be added

  • list_id – The playlist id to be registered

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t playlist_checkout_by_id(playlist_handle_t handle, uint8_t id)

Playlist checkout by list id.

Parameters
  • handle – Playlist handle

  • id – Specified list id

Returns

  • ESP_OK success

  • ESP_FAIL failed

int playlist_get_list_num(playlist_handle_t handle)

Get number of playlists in the handle.

Parameters

handle – Playlist handle

Returns

  • success Number of playlists in handle

  • failed -1

playlist_type_t playlist_get_current_list_type(playlist_handle_t handle)

Get current playlist type.

Parameters

handle – Playlist handle

Returns

  • success Type of current playlist

  • failed -1

int playlist_get_current_list_id(playlist_handle_t handle)

Get current playlist id.

Parameters

handle – Playlist handle

Returns

  • success Current playlist id

  • failed -1

esp_err_t playlist_get_current_list_url(playlist_handle_t handle, char **url_buff)

Get current URL in current playlist.

Parameters
  • handle – Playlist handle

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

int playlist_get_current_list_url_num(playlist_handle_t handle)

Get number of URLs in current playlist.

Parameters

handle – Playlist handle

Returns

Number of URLS in current playlsit

int playlist_get_current_list_url_id(playlist_handle_t handle)

Get current url id in current playlist.

Parameters

handle – Playlist handle

Returns

Current url’s id in current playlsit

esp_err_t playlist_save(playlist_handle_t handle, const char *url)

Save a URL to the current playlist.

Parameters
  • handle – Playlist handle

  • url – The URL to be saved ot sdcard

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t playlist_next(playlist_handle_t handle, int step, char **url_buff)

Next URl in current playlist.

Parameters
  • handle – Playlist handle

  • step – Next steps from current position

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t playlist_prev(playlist_handle_t handle, int step, char **url_buff)

Previous URL in current playlist.

Parameters
  • handle – Playlist handle

  • step – Previous steps from current position

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t playlist_choose(playlist_handle_t handle, int url_id, char **url_buff)

Choose a url by url id.

Parameters
  • handle – Playlist handle

  • url_id – The id of url in current list

  • url_buff[out] A second rank pointer to get a address of URL

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t playlist_show(playlist_handle_t handle)

Show URLs in current playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t playlist_reset(playlist_handle_t handle)

Reset current playlist.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t playlist_remove_by_url(playlist_handle_t handle, const char *url)

Remove corresponding url.

Parameters
  • handle – Playlist handle

  • url – The url to be removed

Returns

  • ESP_OK success

  • ESP_FAIL failed

esp_err_t playlist_remove_by_url_id(playlist_handle_t handle, uint16_t url_id)

Remove url by url id.

Parameters
  • handle – Playlist handle

  • url_id – The id of url to be removed

Returns

  • ESP_OK success

  • ESP_FAIL failed

bool playlist_exist(playlist_handle_t handle, const char *url)

Judge whether the url exists in current playlist.

Parameters
  • handle – Playlist handle

  • url – The url to be checked

Returns

  • true existence

  • false Non-existent

esp_err_t playlist_destroy(playlist_handle_t handle)

Destroy all playlists in the handle.

Parameters

handle – Playlist handle

Returns

  • ESP_OK success

  • ESP_FAIL failed

Structures

struct playlist_operation_t

All types of Playlists’ operation.

Public Members

esp_err_t (*show)(void *playlist)

Show all the URLs in playlist

esp_err_t (*save)(void *playlist, const char *url)

Save URLs to playlist

esp_err_t (*next)(void *playlist, int step, char **url_buff)

Get next URL in playlist

esp_err_t (*prev)(void *playlist, int step, char **url_buff)

Get previous URL in playlist

esp_err_t (*reset)(void *playlist)

Reset the playlist

esp_err_t (*choose)(void *playlist, int url_id, char **url_buff)

Get url by url id

esp_err_t (*current)(void *playlist, char **url_buff)

Get current URL in playlist

esp_err_t (*destroy)(void *playlist)

Destroy playlist

bool (*exist)(void *playlist, const char *url)

Judge whether the url exists

int (*get_url_num)(void *playlist)

Get number of URLS in current playlist

int (*get_url_id)(void *playlist)

Get current url id in playlist

playlist_type_t type

Type of playlist

esp_err_t (*remove_by_url)(void *playlist, const char *url)

Remove the corresponding url

esp_err_t (*remove_by_id)(void *playlist, uint16_t url_id)

Remove url by id

struct playlist_operator_t

Information of playlist manager node.

Public Members

void *playlist

Specific playlist’s pointer

esp_err_t (*get_operation)(playlist_operation_t *operation)

Function pointer to get playlists’ handle

Type Definitions

typedef playlist_operator_t *playlist_operator_handle_t
typedef struct playlist_handle *playlist_handle_t

Enumerations

enum playlist_type_t

Type of playlist.

Values:

enumerator PLAYLIST_UNKNOWN

Unknown type

enumerator PLAYLIST_SDCARD

Playlist in sdcard

enumerator PLAYLIST_FLASH

Playlist in nvs

enumerator PLAYLIST_DRAM

Playlist in ram

enumerator PLAYLIST_PARTITION

Playlist in partition