I load my mp3 via a path into sound pool. For reasons I don’t want to go into I dont want to load via R.raw…
But I get the error:
play(int, float, float, int, int, float) in the type SoundPool is not applicable for the arguments (Object, float, float, int, int, float)
Is there a way to convert the object to an int?
SoundPool mySoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
HashMap mySoundPoolMap = new HashMap<Integer, Integer>();
mySoundPoolMap.put(0, mySoundPool.load("android.resource://com.App.Notifications/raw/myMP3",1));
float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
mySoundPool.play(mySoundPoolMap.get(0), streamVolume, streamVolume, 1, 0, 1f);
Looking at the SoundPool docs there are a couple of ways to add something to a sound pool:
load(AssetFileDescriptor afd, int priority)load(Context context, int resId, int priority)load(String path, int priority)load(FileDescriptor fd, long offset, long length, int priority)Because you don’t want to load a bundled asset you can’t use the either of the first two options. That means you have to use option 3 or 4.
The best option is to probably download the sound file yourself from the url and then save the file and then add the sound to the
SoundPoolusing aFileDescriptorthat points to that file or using theStringthat contains the path of the file.Update: When you add an item to the
SoundPoolusingloadanintis returned. Thisintis a handle to the sound. Then to play the sound you must use thatintto tell theSoundPoolwhich sound you want to play:For example: