Hello Koders ! today Iam introducing MKMusicPlayer Extension
The MKMusicPlayer
extension is a non-visible component that provides audio playback functionality for your MIT App Inventor project. You can play audio files from local storage or a URL, control playback (play, pause, resume, stop), set the playback speed, control volume, and set looping.
The extension requires READ_EXTERNAL_STORAGE
and INTERNET
permissions.
Blocks
AudioLoaded event
The AudioLoaded
event is triggered when the audio is loaded and prepared for playback. It has one parameter, success
, which is a boolean value indicating whether the audio was successfully loaded (true) or not (false).
AudioEnded event
The AudioEnded
event is triggered when the audio playback has finished. It does not have any parameters and does not return any value.
FadeInCompleted
Description: Event triggered when the fade-in effect has completed.
FadeOutCompleted
Description: Event triggered when the fade-out effect has completed.
AudioLoadError
Description: Event is triggered when the MKMusicPlayer fails to load an audio file. It provides an errorMessage detailing the reason for the failure, allowing you to handle the error in your app (e.g., display a message to the user).
LoadAudio
Description: Prepares an audio file from local storage or app assets for playback without automatically starting it. Handles different loading scenarios, errors, and triggers events to indicate loading success (AudioLoaded) or failure (AudioLoadError).
Parameters:
- source (String): The path to the audio file (local storage) or filename (assets).
LoadAudioFromURL
Description: Prepares an online audio file (specified by a URL) for playback without automatically starting it. Handles errors and triggers events to indicate loading success (AudioLoaded) or failure (AudioLoadError).
Parameters:
- audioUrl (String): The URL of the audio file.
PauseAudio`:
- Pause the currently playing audio.
ResumeAudio:
- Start or Resume the paused audio.
StopAudio
- Stop and release the
MediaPlayer
instance.
SetSeekPosition
- (int position): Set the seek position of the audio file in milliseconds.
SetVolumeLevel
(
- int volumeLevel) Control the volume level of the audio in the range of 0 to 100.
SetPlaybackSpeed
- (float speed) Set the playback speed of the audio file. This function is supported on Android devices running API level 23 (Marshmallow) and above.
this takefloat speed
like these values (0.25 , 0.5 , 1 , 1.5 ,2 ,2.5 , 3 )
SetLooping
- (boolean looping)`: Enable or disable looping of the audio.
GetVolumeLevel
- This function retrieves the current volume level of the audio being played by the media player. The volume level is represented as a value ranging from 0 to 100.
GetDuration
- Get the total duration of the audio file in milliseconds.
HasAudioEnded
- Check if the audio file has ended.
GetCurrentPosition
- Get the current seek position of the audio file in milliseconds.
IsLooping
- Check if the audio is set to loop.
IsPlaying
- Check if the audio is currently playing.
FadeIn
-
Description: This function applies a fade-in effect to a media player, gradually increasing the volume from 0 to the final volume level over a specified duration.
By using this function, you can achieve a fade-in effect by gradually increasing the volume of a mediaPlayer from 0 to a specified level over a given duration. -
Parameters:
-
duration
: An integer representing the fade-in duration in milliseconds. -
finalVolume
: An integer representing the desired volume level at the end of the fade-in.
-
FadeOut
-
Description: This function applies a fade-out effect to a media player, gradually decreasing the volume from the initial volume level to 0 over a specified duration.
By using this function, you can achieve a fade-out effect by gradually decreasing the volume of a mediaPlayer from the initial volume level to 0 over a given duration. The mediaPlayer will be paused after the fade-out is completed. -
Parameters:
-
duration
: The duration of the fade-out effect in milliseconds. -
initialVolume
: An integer representing the starting volume level.
-
RestartWithFadeIn
-
Description: Restarts the audio playback with a fade-in effect at the beginning.
-
Parameters:
-
duration
: The duration of the fade-out effect in milliseconds. -
initialVolume
: An integer representing the starting volume level.
-
This MKMusicPlayer will solve these issues
Video
AIX file
You can download it from here :
V1
MKMusicPlayer v1.aix (19.1 KB)
V2
MKMusicPlayer v2.aix (19.3 KB)
V3
MKMusicPlayer v3.aix (35.0 KB)
AIA file
You can download it from here :MKplayer.aia (21.2 KB)
Β© Mr_koder. All rights reserved.
Thanks