Play notification audio by URI

后端 未结 3 673
长情又很酷
长情又很酷 2021-01-05 18:50

I have URI of the notification sound, like content://media/internal/audio/media/122, but SoundPool doesn\'t work with URIs, it works with only apk

3条回答
  •  悲&欢浪女
    2021-01-05 19:11

    Try this to get a full path:

    String path = Environment.getRootDirectory().getAbsolutePath(); //Will return "/system"
    path = path + Uri.getPath().subString(9); //To cut "content:/" from the Uri path.
    //Then pass this "path" to your SoundPool
    

    You are right. Unlike MediaPlayer which is used for music and videos, SoundPool is meant to be used for short app audio resources like notifications. It is much faster and lighter than MediaPlayer.

提交回复
热议问题