How to play InputStream with android SoundPool?

780 Views Asked by At

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.

1

There are 1 best solutions below

2
On BEST ANSWER

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