中文 | English
A simplified encapsulation based on the
audio
module. Supports playlist playback, stopping, and single track playback.
Initialize the function module.
Note:
The play
and loop_play
methods will stop any currently playing audio before starting new playback.
Example:
from player import Player
player = Player(device=0, pa_gpio=2)
Parameters:
Parameter | Type | Description |
---|---|---|
device | int | Audio channel number, default is 0 |
pa_gpio | int | Volume control GPIO number |
Audio playback callback
Example:
def audio_cb(self, event):
if event == 0:
logger.info('audio play start.')
elif event == 7:
logger.info('audio play finish.')
Parameters:
Parameter | Type | Description |
---|---|---|
event | int | Event type (0: start playback; 1: end playback) |
Execute playback
Example:
# Play a single track
player.loop_play('music1.mp3')
Parameters:
Parameter | Type | Description |
---|---|---|
song | str | Audio file path |
Infinite loop playback of a playlist.
Example:
# The playlist is a list of file paths, which will be played in an infinite loop.
player.loop_play(['music1.mp3', 'music2.mp3'])
Parameters:
Parameter | Type | Description |
---|---|---|
song_sheet | list | List of audio files |
Single track playback.
Example:
player.play('music3.mp4')
Parameters:
Parameter | Type | Description |
---|---|---|
song | str | Audio file path |
Stop playback
Set volume
Example:
# Set volume level to 11
player.setVolume(11)
Parameters:
Parameter | Type | Description |
---|---|---|
level | int | Volume level: 0~11, where 0 means mute |