Player - Device Audio, Loop - Play Streaming

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


component_method (4)

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");
    

component_method (13)

PlayFromAssets

Plays an audio file from the project's assets.


component_method (11)

Pause

Pauses the current audio playback.


component_method (17)

Stop

Stops the current audio playback and resets the pause position.


component_method (14)

Resume

Resumes playback from the last pause position or from the beginning if it’s an asset file.


component_method (8)

GetAllMusicFiles

Retrieves all MP3 music files on the device with details such as path, name, artist, album, and duration.


component_method (6)

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.


component_method (15)

SeekTo

Seeks to a specific position in the audio in milliseconds.


component_method (9)

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.


component_event (9)

OnPlay

Triggered when audio playback starts.


component_event (5)

OnPause

Triggered when audio playback is paused.


component_event (4)

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


component_method (35)

StartService

Starts the foreground player service.


component_method (36)

StopService

Stops the foreground player service.


component_set_get (2)

isPlaying

Returns true if the media player is currently playing.


blocks (37)

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.

component_method (49)

SetPlaylist

Set a list of songs.

  • songs: List of song paths.

component_method (50)

GetPlaylist

Get the list of songs set in SetPlaylist.


blocks (55)

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

blocks (53)

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.

Minutes to milliseconds example:


component_method (46)

DisableLoop

Disable loop playback, the song will continue to play normally.


component_method (51)

GetSongsCount

Get the number of songs in the playlist in the app.


blocks (51)

Shuffle

Set songs to shuffle mode.


component_method (48)

Next

Go to the next song.
Shuffle mode applies to Next if enabled.


component_method (47)

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.


component_set_get (3)

CurrentSongIndex

Get the index of the currently playing song.


EVENT

OnSongIndexChanged

Event is fired when a new song starts by getting its index.


component_event (25)

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.

component_event (22)

OnSetPlaylist

Event triggered when playlist of songs is complete.


component_event (20)

OnNext

The event is fired when using the Next function.


component_event (21)

OnPrevious

The event is fired when using the Previous function.


ă…€Extension: Version: 1.0.6ă…€
joejsanz.player.joedevplayer.aix (1.6 MB)


Thanks.

11 Likes

Hola @Joejsanz .

He visto que la extension reproduce (local files)
Pregunto. ÂżQue tipo de formatos reproduce?
Lo pregunto por curiosidad, no estoy por hacer ningĂșn proyecto que involucre el uso de audio pero me genero duda. Hace tiempo que estoy buscando alguna extension que maneje mp3s de forma fluida, pero no he tenido suerte con los que encontrĂ©, no se ajustaron a mis necesidades pasadas.
En fin. Va un like por el proyecto.
Pd. Generalmente no escribo en castellano, pero sabiendo que sos de Mexico me pareciĂł correcto escribirlo asĂ­.

1 Like

Means?

is this able to control streaming services too? Like Spotify for example.

Muchas gracias @German_Skena

Los formatos que puede agarrar son:

  • MP3 (.mp3)
  • WAV (.wav)
  • AAC (.aac)
  • MIDI (.mid, .midi)
  • OGG (.ogg)
  • AMR-NB (.amr)
  • AMR-WB (.awb)

Estos Ășltimos 3, la disponibilidad puede variar segĂșn el dispositivo Android y sus cĂłdecs especĂ­ficos.

  • FLAC (.flac)
  • 3GP (.3gp)
  • M4A (.m4a): MPEG-4 Audio

.flac no lo he probado, pero los 2 Ășltimos agarran bien en mi dispositivo android 11.

1 Like

Right now it's not possible, I have not tested that function, I will investigate that.
@Damiano_Zedda

1 Like
1 Like

Hmm, where is the .Play method for audio files from external storage?

(I checked and found that the "url" socket can also be used for an absolute path. But it is at least confusing.)

1 Like

Admittedly it's confusing since it accepts an absolute path, I'll change it to say path.

Today I realized that my memory card is damaged and only receives music from the internal storage,

I'm going to look at that and add that feature.

Regarding internal and external storage see here: Some basics on Android storage system

I have formatted my memory card and I have verified that the GetAllMusicFiles function effectively captures all the mp3 music on the device, internal and external.

I also changed the name of the .Play function parameter and added usage examples.

This is a full path, not an absolute path. Maybe it's working with that too. I didn't check. But if this works too, it might also work with the PrivateDir. I'll check later...

1 Like

Thank you so much Anke

Where is the new exension version?

Did you check your extension with the APK? There are permission errors (at least on Android 13+).

I'll check that out later, as soon as I can get the computer.

I think I missed adding this READ_MEDIA_AUDIO for when it is android 13+

1 Like

Yes, but even if I request this permission (i.e. automatically declare it in the Manifest), a storage permission error is thrown.

Please check your extensions beforehand also with the compiled app.

I've been struggling to get my laptop to work, it only lasts 2 minutes and turns off, I think I'll need another one, anyway...
I haven't been able to review the code, but if I'm not mistaken, the code fails because I didn't set the READ_MEDIA_AUDIO permission to the Manifest when creating the extension.

I don't think so, because (as I already said) I declared this permission in the Manifest, requested it und got the permission error anyway.

1 Like

Find a program to monitor CPU heat.
Sounds like a clogged or failing fan.

1 Like