Player
Get all the music from your device or from Assets.
Play audio from URLs, local files, and project assets.
Pause, stop, resume, and adjust volume during playback.
Retrieve detailed information about audio files including paths, names, artists, albums, and durations from both device storage and assets.
Convert time formats between minutes and seconds and milliseconds, and manage playback positions.
The Android SDK's MediaPlayer class is being used for audio playback.
For the Assets option, you need to create a .txt document with the same name as the song that is in assets with this modified information inside:
Artist: Jet
Album: Jet
Duration: 00:00
Functions
Play
Plays an audio file from a URL or absolutePath.
Example Usages:
- Playing a local file from external storage:
Play("/storage/emulated/0/Music/song.mp3");
- Playing a file from the web:
Play("https://www.example.com/path/to/song.mp3");
PlayFromAssets
Plays an audio file from the project's assets.
Pause
Pauses the current audio playback.
Stop
Stops the current audio playback and resets the pause position.
Resume
Resumes playback from the last pause position or from the beginning if itâs an asset file.
GetAllMusicFiles
Retrieves all MP3 music files on the device with details such as path, name, artist, album, and duration.
GetAllAssetMusicFiles
Retrieves all MP3 music files from the project's assets with details such as path, name, artist, album, and duration.
ConvertToMilliseconds
Converts a time in minutes and seconds to milliseconds.
ConvertToMinutesAndSeconds
Converts milliseconds to minutes and seconds.
SeekTo
Seeks to a specific position in the audio in milliseconds.
GetCurrentPosition
Retrieves the current playback position of the audio in milliseconds.
Events
OnAssetMusicFilesRetrieved
Triggered when all music files from the project's assets have been retrieved, providing lists of paths, names, artists, albums, and durations.
OnPlay
Triggered when audio playback starts.
OnPause
Triggered when audio playback is paused.
OnStop
Triggered when audio playback is stopped.
New functions: StartService
, StopService
, SetNotificationContent
, and isPlaying
.
You can now turn off the screen without entering Doze mode.
A foregroundService is being used.
Tested on Xiaomi Redmi Note, Android 11 and Android 14.
min_sdk: 26
build_target: 34
StartService
Starts the foreground player service.
StopService
Stops the foreground player service.
isPlaying
Returns true
if the media player is currently playing.
SetVolume
Sets the volume of the left and right channels of the media player.
Each channel can be configured separately.
Volume value:
0.0
Mute volume
1.0
Maximum volume
Default value: 0.5
The floating notification is now fully clickable with the Play/Pause action.
The SetNotificationContent function is back to normal, with only 2 parameters.
SetNotificationContent
Sets the title and content for the notification that is displayed while the service is running.
The SetNotificationContent
block is optional, but defaults to these values:
title:
Playing
content:
Audio playback in progress
GetAlbumArt
Get the cover art for the songs on your device.
songPath
: The path of the song on the device.
imageIfThereIsntOne
: An image from assets that will appear if the song has no cover art.
ă € Update, Jan. 04, 2025. - Version: 1.0.5 ă €
Note:
GetAllMusicFiles
and OnMusicFilesRetrieved
have changed...
You will need to locate the blocks in your project if you are using them so you don't lose their functionality.
Removed the GetAllAudioFiles
function and the OnAudioFilesRetrieved
event that got all audio file types from the device, since it is not needed because now the GetMusicFiles function does that.
FUNCTIONS
ă
€ Added Helper-Block to GetMusicFiles.ă
€ V1.0.6
Jan. 05, 2025.
GetMusicFiles
The GetAllMusicFiles function has been renamed to GetMusicFiles and a parameter has been added to set the type of audio file you want to get.
audioType
: "MP3"
Input types: MP3, AAC, WAV, OGG, AMR, FLAC, MIDI, MP4, M4A, MKA.
- Setting
All
will get all audio types.
SetPlaylist
Set a list of songs.
songs
: List of song paths.
GetPlaylist
Get the list of songs set in SetPlaylist.
PlaybackSpeed
Set the playback speed (0.5 to 2.0 recommended).
speed
: The number must be greater than 0.0.
Repeat
Set the repeat mode.
repeatMode
:RepeatMode
helper block with these options:
repeatAll
repeatOne
repeatOff
Loop:
Calling the function causes playback to loop for the time set in the start and end parameters.
-
start
: Start time in milliseconds. -
end
: End time in milliseconds.- The set song segment will not stop playing until you call the
DisableLoop
function.
- The set song segment will not stop playing until you call the
Minutes to milliseconds example:
DisableLoop
Disable loop playback, the song will continue to play normally.
GetSongsCount
Get the number of songs in the playlist in the app.
Shuffle
Set songs to shuffle mode.
Next
Go to the next song.
Shuffle mode applies to Next if enabled.
Previous
Go back to the previous song.
Shuffle mode does not apply here, the song will be returned to the index before the current one.
CurrentSongIndex
Get the index of the currently playing song.
EVENT
OnSongIndexChanged
Event is fired when a new song starts by getting its index.
OnPlaybackComplete
Event is fired when a song ends, except in RepeatOne mode.
OnMusicFilesRetrieved
It's activated when all music files have been retrieved from the device and provides lists of paths, titles, artists, albums, durations and bitRates.
bitRates
- New parameter.
OnSetPlaylist
Event triggered when playlist of songs is complete.
OnNext
The event is fired when using the Next function.
OnPrevious
The event is fired when using the Previous function.
ă
€Extension: Version: 1.0.6ă
€
joejsanz.player.joedevplayer.aix (1.6 MB)
Thanks.