The MediaPlayer object can be used to play sound files from the phone or tablet.
ply = app.CreateMediaPlayer() → app object: MediaPlayer
Use the SetFile method of the MediaPlayer object to set the sound file to play. Supported sound file types include .ogg and .mp3.
When the sound file is ready for playback, the OnReady callback function will be called. Then you can start playing using the Start method.
If the sundtrack has finished playing, the OnComplete callback fill be called. All together you code could look like that:
Example - Playing Audio
player = app.CreateMediaPlayer();
player.SetOnComplete( player_OnComplete );
player.SetFile( "/Sys/Snd/Poing.ogg" );
app.ShowPopup( "OnComplete" );
The SeekTo method can be used to adjust the playback position by passing in the time in seconds. Passing in 0 will set the playback position to the beginning of the sound file: player.SeekTo( 0 );
The following methods are available on the MediaPlayer object:
string: path to file or folder ( “/absolute/...” or “relative/...” )
string: “screen”, “px”
Close the media player and thus make it unuseable for further use.
Returns the total duration of the currently loaded song in seconds.
Returns data about the position and size of the control.
If the screen option is given the position on the screen will be returned. Otherwise relative to the parent control.
The px options turns the relative values into pixels.
Returns the control class name.
Checks if the media player will replay the song from the begining if it has finished.
Checks if the media player is currently playing.
Checks if the media player is ready for use.
Pause the current playing song.
Play the current loaded song from the last paused time or from a given start time in in seconds.
Seek the player to a given time in seconds.
Load a sound file to the media player.
Define whether the media player should replay the song when completed.
Define a callback function which is called when a playing sound file has finished playing.
Define a callback function which is called when the player is ready for use.
Define a callback function which is called when a seeking process is done.
Change the volume of the playing song.
Stop playing a song.