You can get all the necessary meta data using mediametadataretriever. In the below code we have used the getcurrentposition method to get the current playback position and getduration to get the duration of the audio file.
Vir us nov 2 15 at 18 13.
How to get duration of audio file in android. Int total duration mediaplayer getduration. See my answer below for more details. No need to create a mediaplayer instance just to get the media duration.
Start date jun 2 2015. Public class soundutility param context param soundfile sound file object can be one of. Adding the demo sound file to your android audio app.
Currently that is the mobile device speaker or a bluetooth headset. You can use the mediametadataretriever to get the duration of a song. Use the metadata key duration in combination with the extractmetadata funciton.
Once we are done with our interface we have to add the audio file to our project. Android get duration of audio file. You can play back the audio data only to the standard output device.
If there is no raw folder then create it by right clicking on res new directory. The following classes are used to play sound and video in the android framework. You have to add the files to the raw folder.
Similar threads b4a question audio library beeper duration b4a library audio library v1 5 new audiostreamer object b4a tutorial accessing third party jar with additionaljar and javaobject picasso b4a tutorial walkie talkie audio. Mediaplayer mp new. Integer resource id string file path or file return duration of given sound file in millis 0 if failed public static long getdurationofsound context context object soundfile int millis 0.
You can find it here app res raw. Int current pos mediaplayer getcurrentposition. Android question how to get audio file time duration.
You cannot play sound files in the conversation audio during a call.