Player - Device Audio, Loop - Play Streaming

Player

Play music with the MediaPlayer SDK.
Developed by Joe using Fast.

  • Get all the music from your device or from Assets.
  • Play audio from URLs, local files, and project assets.

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.

  • 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

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 (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.


component_method (35)

StartService

Starts the foreground player service.

component_method (36)

StopService

Stops the foreground player service.

  • You can turn off the screen without entering Doze mode.
    A foregroundService is being used.

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


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.


ă…€ Added Helper-Block to GetMusicFiles.ă…€ V1.0.6
Jan. 05, 2025.

GetMusicFiles

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 (2)

isPlaying

Returns true if the media player is currently playing.


component_set_get (3)

CurrentSongIndex

Get the index of the currently playing song.


Events

OnMusicFilesRetrieved

It's activated when all music files have been retrieved from the device and provides lists of:

  • paths, titles, artists, albums, durations, tracks, years, genres, composers, sizes, displayNames and bitRates.

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.


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.


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.



Update, v1.0.8
Jan. 19, 2025.

In Android prior to 13 the notification could not be dismissed, but that changed in Android 14, now the user can dismiss the notification, Google put it that way.

So I decided to make it so that when the notification is dismissed the music and the service stops.


Note:

  • I had to remove the play and pause feature when clicking on the notification, as it interfered with stopping the music and service when swiping.

component_method (55)
Adjust the MediaPlayer playback pitch.

  • 1.0 is normal pitch, recommended: 0.5 to 2.0.

Update, v1.0.9
Jan. 23, 2025.

Audio focus was updated.

  • The music kept playing even when there was another player active or you played this one and the other's audio didn't stop.
    • That's now fixed.

component_event (30)

OnAudioFocusLost

Fired when audio focus is lost.


Update to floating notification:

Tested on Android 14 and 11.

  • Added Album Art display.

  • Established that if it's the last song in the playlist, when it's finished, the service stops and consequently the notification closes, since it didn't.

  • Added display of the elapsed time of the song, when pausing it will only show Now, but when calling Resume it will continue moving forward from where it was paused.

    • This only appears on Android 14 and not on Android 11.

Android 11

Android 14


SetNotificationAlbumArt

Get the song's cover art to be displayed in the notification.

  • songPath: Path to the song.
  • imageIfTherIsntOne: If there is no cover art embedded in the song, an image is set from the assets.

Update, v1.1.0
Feb 01, 2025.

AudioSessionId

Returns the audio session ID.

component_set_get (5)

A small update, needed to be able to use this Player with an Equalizer I created separately.

  • When playing audio, you are given a session ID, when you stop the audio, that ID is lost.
    Pausing does not lose the ID.

ă…€Extension: Version: 1.1.0ă…€ Feb 01, 2025.
joejsanz.player.joedevplayer.aix (942.1 KB)


minSdk: 26
maxSdk: 34
JDK: 11


Thanks.
13 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