Android Soundpool Load(String path, int priority)

android, audio, resources, soundpool

Solution

Simple working way of doing so with a context named `mContext`. It loads the resource by name by getting the identifier id at run-time.

int sound_id = mContext.getResources().getIdentifier("myownsound", "raw",
                                                     mContext.getPackageName());
soundPool.load(mContext, sound_id, 1);

It also works to load drawables or xml files, by replacing `"raw"` by `"drawable"` or `"xml"` for example.

Problem

I am trying to load a sound from android. The sound is under `res/raw/myownsound.wav`. I know that I can already load the sound using: ``` soundPool.load(context, R.raw.myownsound, 1) ``` For customization purposes, I would like to load it using: ``` soundPool.load("res/raw/myownsound", 1) ``` ... but I get the following error : `error loading res/raw/myownsound`. I also tried the following : ``` soundPool.loadSound("android.resource://upg.GraphismeBase/raw/myownsound", 1) ``` .. but I get an error as well : `error loading android.resource://upg.GraphismeBase/raw/myownsound` What is the correct way of using soundPool.load(path, priority) ?

Original source