What is the best way to get an audio file duration in Android?

前端 未结 3 1501
星月不相逢
星月不相逢 2020-12-16 00:37

I\'m using a SoundPool to play audio clips in my app. All is fine but I need to know when the clip playback has finished.

At the moment I track it in my app by obta

3条回答
  •  孤街浪徒
    2020-12-16 01:24

    Did you try this:

    String mediaPath = Uri.parse("android.resource:///raw/filename").getPath();
    MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    mmr.setDataSource(mediaPath);
    String duration = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
    mmr.release();
    

    But i am not exactly sure that this is lighter than exisiting code.

提交回复
热议问题