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
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");
PlayFromAssets
Description: Plays an audio file from the project's assets.
Pause
Description: Pauses the current audio playback.
Stop
Description: Stops the current audio playback and resets the pause position.
Resume
Description: Resumes playback from the last pause position or from the beginning if itâs an asset file.
SetVolume
Description: Sets the volume of the media player.
GetAllAudioFiles
Description: Retrieves all audio files on the device, including formats like MP3, WAV, etc.
GetAllMusicFiles
Description: Retrieves all MP3 music files on the device with details such as path, name, artist, album, and duration.
GetAllAssetMusicFiles
Description: Retrieves all MP3 music files from the project's assets with details such as path, name, artist, album, and duration.
Description: Triggered when all music files from the project's assets have been retrieved, providing lists of paths, names, artists, albums, and durations.
Description: Triggered when all MP3 music files from the device have been retrieved, providing lists of paths, names, artists, albums, and durations.
OnPlay
Description: Triggered when audio playback starts.
OnPause
Description: Triggered when audio playback is paused.
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.
Update Octuber 28, 2024
This update ensures that the CPU remains active during music playback, preventing the system from suspending the process while music is playing in the background or with the screen off.
This should help prevent playback from stopping on its own during extended sessions.
When playback is paused or stopped, the CPU is freed up.
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...
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.