Search code examples
androidsoundpool

How to play InputStream with android SoundPool?


Sound is not asset, that's why I get it as InputStream:

InputStream is = getClass().getClassLoader().getResourceAsStream("sound.ogg");

How to play java.io.InputStream with android.media.SoundPool?

In class android.media.SoundPool I've found 4 methods to load sound

public int load(String path, int priority);
public int load(AssetFileDescriptor afd, int priority);
public int load(Context context, int resId, int priority);
public int load(FileDescriptor fd, long offset, long length, int priority);

but anything works with InputStream.


Solution

  • Create AssetFileDescriptor: afd = context.getAssets().openFd("sound.ogg"); And call load method: soundPool.load(afd, 1);