class Player

Audio player now can support mp3,amr and wav, if more types are needed, please add the decoder in function audio_player_create.

class audio.Player

Constructors

class audio.Player([state_callback])

Create a Player, state_callback is a monitor of player state, when state changed, this callback will be invoked.

UIFLOW2:

init.png

Methods

Player.play(uri, pos=0, volume=-1, sync=True, verify=None)

Play the audio file.

Parameters:

UIFLOW2:

play_local_file.png

play_local_file1.png

play_sdcard_file.png

play_cloud_file.png

Player.play_raw(data, sample=16000, stereo=False, bits=16, pos=0, volume=-1, sync=True)

Play the raw audio data.

Parameters:
  • data (bytes) – The raw audio data.

  • sample (int) – The sample rate of the audio data.

  • stereo (bool) – Whether the audio data is stereo.

  • bits (int) – The bits of the audio data.

  • pos (int) – The position to start playing, in byte.

  • volume (int) – The volume of the player, 0-100. -1 means the default volume.

  • sync (bool) – Whether to play synchronously.

UIFLOW2:

play_raw.png

Player.play_tone(freq, time, volume=-1, sync=True)

Play a tone.

Parameters:
  • freq (int) – The frequency of the tone.

  • time (float) – The duration of the tone.

  • volume (int) – The volume of the player, 0-100. -1 means the default volume.

  • sync (bool) – Whether to play synchronously.

UIFLOW2:

play_tone.png

Player.pause()

Pause the player.

UIFLOW2:

pause.png

Player.resume()

Resume the player.

UIFLOW2:

resume.png

Player.stop()

Stop the player.

UIFLOW2:

stop.png

Player.pos()

Get the position of the player.

Returns:

The position of the player.

UIFLOW2:

pos.png

Player.set_vol(volume)

Set the volume of the player.

Parameters:

volume (int) – The volume of the player, 0-100.

UIFLOW2:

set_vol.png

Player.get_vol()

Get the volume of the player.

Returns:

The volume of the player.

UIFLOW2:

get_vol.png