Player - External Audio and Asset Player

The extension provides a robust media player for Android applications, offering functionalities for:

  • Playback: Play audio from URLs, local files, and project assets.
  • Control: Pause, stop, resume, and adjust volume during playback.
  • File Management: Retrieve detailed information about audio files including paths, names, artists, albums, and durations from both device storage and assets.
  • Metadata Handling: Convert time formats between minutes and seconds and milliseconds, and manage playback positions.

The extension uses the MediaPlayer class from the Android SDK 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)

  1. Play
    • Description: 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)

  1. PlayFromAssets
    • Description: Plays an audio file from the project's assets.

component_method (11)

  1. Pause
    • Description: Pauses the current audio playback.

component_method (17)

  1. Stop
    • Description: Stops the current audio playback and resets the pause position.

component_method (14)

  1. Resume
    • Description: Resumes playback from the last pause position or from the beginning if it’s an asset file.

component_method (16)

  1. SetVolume
    • Description: Sets the volume of the media player.

component_method (7)

  1. GetAllAudioFiles
    • Description: Retrieves all audio files on the device, including formats like MP3, WAV, etc.

component_method (8)

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

component_method (6)

  1. GetAllAssetMusicFiles
    • Description: Retrieves all MP3 music files from the project's assets with details such as path, name, artist, album, and duration.

  1. ConvertToMilliseconds
    • Description: Converts a time in minutes and seconds to milliseconds.

  1. ConvertToMinutesAndSeconds
    • Description: Converts milliseconds to minutes and seconds.

component_method (15)

  1. SeekTo
    • Description: Seeks to a specific position in the audio in milliseconds.

component_method (9)

  1. GetCurrentPosition
    • Description: Retrieves the current playback position of the audio in milliseconds.

Events

  1. OnAudioFilesRetrieved
    • Description: Triggered when all audio files from the device have been retrieved, providing lists of paths, names, artists, albums, and durations.

  1. OnAssetMusicFilesRetrieved
    • Description: Triggered when all music files from the project's assets have been retrieved, providing lists of paths, names, artists, albums, and durations.

  1. OnMusicFilesRetrieved
    • Description: Triggered when all MP3 music files from the device have been retrieved, providing lists of paths, names, artists, albums, and durations.

component_event (9)

  1. OnPlay
    • Description: Triggered when audio playback starts.

component_event (5)

  1. OnPause
    • Description: Triggered when audio playback is paused.

component_event (4)

  1. OnStop
    • Description: Triggered when audio playback is stopped.


Update August 27, 2024

  • When receiving a call, the music continued to play.

This has been fixed. Now when receiving a call, the music pauses, and when the call ends, the music resumes.



Extension: Update (bugs fixed). Nov. 13, 2024.
joejsanz.player.joedevplayer.aix (21.2 KB)


Thanks.

10 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