Developer World
Spresense Arduino Library v3.3.0-b2e6327
MediaPlayer Class Reference

MediaPlayer Class Definitions. More...

#include <MediaPlayer.h>

Public Types

enum  PlayerId { Player0 , Player1 }
 Audio library allows you to use two players simultaneously. Please set Player ID that player instance id created to use. More...
 

Public Member Functions

err_t begin (void)
 Initialize the MediaPlayer. More...
 
err_t end (void)
 Finalize the MediaPlayer. More...
 
err_t create (PlayerId id)
 Creation of the MediaPlayer. More...
 
err_t create (PlayerId id, AudioAttentionCb attcb)
 Creation of the MediaPlayer. More...
 
err_t activate (PlayerId id, MediaPlayerCallback mpcb)
 Activate the MediaPlayer. More...
 
err_t activate (PlayerId id, uint8_t output_device, MediaPlayerCallback mpcb)
 Activate the MediaPlayer (old interface) More...
 
err_t activate (PlayerId id, MediaPlayerCallback mpcb, uint32_t player_bufsize)
 Activate the MediaPlayer. More...
 
err_t activate (PlayerId id, uint8_t output_device, MediaPlayerCallback mpcb, uint32_t player_bufsize)
 Activate the MediaPlayer (Old compatible) More...
 
err_t init (PlayerId id, uint8_t codec_type, uint32_t sampling_rate, uint8_t channel_number)
 Initialize the MediaPlayer (Abridged version). More...
 
err_t init (PlayerId id, uint8_t codec_type, uint32_t sampling_rate, uint8_t bit_length, uint8_t channel_number)
 Initialize the MediaPlayer (Abridged version). More...
 
err_t init (PlayerId id, uint8_t codec_type, const char *codec_path, uint32_t sampling_rate, uint8_t channel_number)
 Initialize the MediaPlayer (Abridged version). More...
 
err_t init (PlayerId id, uint8_t codec_type, const char *codec_path, uint32_t sampling_rate, uint8_t bit_length, uint8_t channel_number)
 Initialize the MediaPlayer. More...
 
err_t start (PlayerId id, DecodeDoneCallback dccb)
 Start playing. More...
 
err_t stop (PlayerId id)
 Stop playing. More...
 
err_t stop (PlayerId id, uint8_t mode)
 Stop playing (Stop mode specify). More...
 
err_t reqNextProcess (PlayerId id, AsRequestNextType type)
 Request next process to player. More...
 
err_t deactivate (PlayerId id)
 Deactivate the MediaPlayer. More...
 
err_t writeFrames (PlayerId id, File &myfile)
 Write(Supply) audio data to play. More...
 
err_t writeFrames (PlayerId id, uint8_t *data, uint32_t size)
 Write(Supply) audio data to play. More...
 

Static Public Member Functions

static MediaPlayergetInstance ()
 Get instance of MediaRecorder for singleton.
 

Detailed Description

MediaPlayer Class Definitions.

Member Enumeration Documentation

◆ PlayerId

Audio library allows you to use two players simultaneously. Please set Player ID that player instance id created to use.

Enumerator
Player0 

Indicates Player0

Player1 

Indicates Player1

Member Function Documentation

◆ begin()

err_t MediaPlayer::begin ( void  )

Initialize the MediaPlayer.

This function is called only once when using the MediaPlayer. In this function, alloc memory area of FIFO for ES data supply.

◆ end()

err_t MediaPlayer::end ( void  )
inline

Finalize the MediaPlayer.

This function is called only once when finish the MediaPlayer.

◆ create() [1/2]

err_t MediaPlayer::create ( PlayerId  id)

Creation of the MediaPlayer.

This function is called only once when using the MediaPlayer. In this function, create objcets for audio data decoding.

Parameters
idSelect Player ID.

◆ create() [2/2]

err_t MediaPlayer::create ( PlayerId  id,
AudioAttentionCb  attcb 
)

Creation of the MediaPlayer.

This function can set callback funtion which receive attention notify.

Parameters
idSelect Player ID.
attcbAttention callback

◆ activate() [1/4]

err_t MediaPlayer::activate ( PlayerId  id,
MediaPlayerCallback  mpcb 
)

Activate the MediaPlayer.

This function activates media player system. The result of APIs will be returnd by callback function which is specified by this function.

Parameters
idSelect Player ID.
mpcbSepcify callback function which is called to notify API results.

◆ activate() [2/4]

err_t MediaPlayer::activate ( PlayerId  id,
uint8_t  output_device,
MediaPlayerCallback  mpcb 
)

Activate the MediaPlayer (old interface)

This function activates media player system. The result of APIs will be returnd by callback function which is specified by this function.

Parameters
idSelect Player ID.
output_deviceSet output device.(not supported)
mpcbSepcify callback function which is called to notify API results.

◆ activate() [3/4]

err_t MediaPlayer::activate ( PlayerId  id,
MediaPlayerCallback  mpcb,
uint32_t  player_bufsize 
)

Activate the MediaPlayer.

This API works as same as activate(id, mpcb), but you can set buffer size of player.

Parameters
idSelect Player ID.
mpcbSepcify callback function which is called to notify API results.
player_bufsizebuffer size of player

◆ activate() [4/4]

err_t MediaPlayer::activate ( PlayerId  id,
uint8_t  output_device,
MediaPlayerCallback  mpcb,
uint32_t  player_bufsize 
)

Activate the MediaPlayer (Old compatible)

This API works as same as activate(id, output_device, mpcb), but you can set buffer size of player.

Parameters
idSelect Player ID.
output_deviceSet output device.(not supported)
mpcbSepcify callback function which is called to notify API results.
player_bufsizebuffer size of player

◆ init() [1/4]

err_t MediaPlayer::init ( PlayerId  id,
uint8_t  codec_type,
uint32_t  sampling_rate,
uint8_t  channel_number 
)

Initialize the MediaPlayer (Abridged version).

This is abridged version on initialize API. You can init media player with codec type, sampling rate, and number of channels. When this API is called, other parameters are fixed as below.

Bit length : 16bit DSP binary path : /mnt/sd0/BIN

Parameters
idSelect Player ID.
codec_typeSet compression code. AS_CODECTYPE_MP3 or AS_CODECTYPE_WAV
sampling_rateSet sampling rate. AS_SAMPLINGRATE_XXXXX
channel_numberSet channnel number. AS_CHANNEL_MONO or AS_CHANNEL_STEREO

◆ init() [2/4]

err_t MediaPlayer::init ( PlayerId  id,
uint8_t  codec_type,
uint32_t  sampling_rate,
uint8_t  bit_length,
uint8_t  channel_number 
)

Initialize the MediaPlayer (Abridged version).

This is abridged version on initialize API. If you would like to set all of decode parameters but DSP binary path can be default, you can call this API. DSP binary path will be defautl as below.

DSP binary path : /mnt/sd0/BIN

Parameters
idSelect Player ID.
codec_typeSet compression code. AS_CODECTYPE_MP3 or AS_CODECTYPE_WAV
sampling_rateSet sampling rate. AS_SAMPLINGRATE_XXXXX
bit_lengthSet bit length. AS_BITLENGTH_16 or AS_BITLENGTH_24
channel_numberSet channnel number. AS_CHANNEL_MONO or AS_CHANNEL_STEREO

◆ init() [3/4]

err_t MediaPlayer::init ( PlayerId  id,
uint8_t  codec_type,
const char *  codec_path,
uint32_t  sampling_rate,
uint8_t  channel_number 
)

Initialize the MediaPlayer (Abridged version).

This is abridged version on initialize API. If you would like to set DSP binary path but bit length paramter can be default, you can call this API. Bit length parameter will be defautl as below.

DSP binary path : /mnt/sd0/BIN

Parameters
idSelect Player ID.
codec_typeSet compression code. AS_CODECTYPE_MP3 or AS_CODECTYPE_WAV
codec_pathSet DSP binary placement path
sampling_rateSet sampling rate. AS_SAMPLINGRATE_XXXXX
channel_numberSet channnel number. AS_CHANNEL_MONO or AS_CHANNEL_STEREO

◆ init() [4/4]

err_t MediaPlayer::init ( PlayerId  id,
uint8_t  codec_type,
const char *  codec_path,
uint32_t  sampling_rate,
uint8_t  bit_length,
uint8_t  channel_number 
)

Initialize the MediaPlayer.

This is full version on initialize API. You can set all of decode parameters. Before you start playing, you must initialize media player by this API or abridge versions of this APS.

Parameters
idSelect Player ID.
codec_typeSet compression code. AS_CODECTYPE_MP3 or AS_CODECTYPE_WAV
codec_pathSet DSP binary placement path
sampling_rateSet sampling rate. AS_SAMPLINGRATE_XXXXX
bit_lengthSet bit length. AS_BITLENGTH_16 or AS_BITLENGTH_24
channel_numberSet channnel number. AS_CHANNEL_MONO or AS_CHANNEL_STEREO

◆ start()

err_t MediaPlayer::start ( PlayerId  id,
DecodeDoneCallback  dccb 
)

Start playing.

This function starts playing audio data. When you call this API, player system pull out audio data from FIFO. So, you have to push audio data which will play into FIFO by "write frame API". Decode completion and decodec data will be notified by callback function which is specified by this API. You can process them.

Parameters
idSelect Player ID.
dccbCallback function for notify decode completion

◆ stop() [1/2]

err_t MediaPlayer::stop ( PlayerId  id)

Stop playing.

This function stops playing audio data. You can call this API when playing is activate. When you call this API, return of API will back soon but internal work cannot stop immediately. So, after API call, decodec data will be returned to application while supplied data runs out. It is better to process them.

◆ stop() [2/2]

err_t MediaPlayer::stop ( PlayerId  id,
uint8_t  mode 
)

Stop playing (Stop mode specify).

This function stops playing audio data with stop mode. Stop mode is "Wait ES ends : stop after play all of supplied data and reply result" and "Immediately stop : stop soon". You can set either of them.

Parameters
idSelect Player ID.
modeSet stop mode. AS_STOPPLAYER_NORMAL or AS_STOPPLAYER_ESEND

◆ reqNextProcess()

err_t MediaPlayer::reqNextProcess ( PlayerId  id,
AsRequestNextType  type 
)

Request next process to player.

This function requests next process to player. You should call this API at timing of next decode can be done. For example, timing of decoded data rendering is done.

Parameters
idSelect Player ID.
typeSet Request type. AsNextNormalRequest or AsNextStopResRequest

◆ deactivate()

err_t MediaPlayer::deactivate ( PlayerId  id)

Deactivate the MediaPlayer.

This function deactivates media player system.

◆ writeFrames() [1/2]

err_t MediaPlayer::writeFrames ( PlayerId  id,
File myfile 
)

Write(Supply) audio data to play.

This function supplies audio data to player system. When you call this API, player read "myfile" and supply audio data to FIFO and the data will be decoded. If you do not, FIFO will occuers underflow.

Parameters
idSelect Player ID.

◆ writeFrames() [2/2]

err_t MediaPlayer::writeFrames ( PlayerId  id,
uint8_t *  data,
uint32_t  size 
)

Write(Supply) audio data to play.

This function works as same as above writeFrames(PlayerId, File &). However, take audio data from buffer, not from file.

Parameters
idSelect Player ID.
dataPointer to audio data which would like to sound
sizeSize of audio data

The documentation for this class was generated from the following file: