SoundPool.load() and FileDescriptor from file
Posted
by Hans
on Stack Overflow
See other posts from Stack Overflow
or by Hans
Published on 2010-06-04T22:52:53Z
Indexed on
2010/06/05
10:12 UTC
Read the original article
Hit count: 283
I tried using the load function of the SoundPool that takes a FileDescriptor, because I wanted to be able to set the offset and length. The File is not stored in the Ressources but a file on the storage card. Even though neither the load nor the play function of the SoundPool throw any Exception or print anything to the console, the sound is not played. Using the same code, but use the file path string in the SoundPool constructor works perfectly.
This is how I have tried the loading (start equals 0 and length is the length of the file in miliseconds):
FileInputStream fileIS = new FileInputStream(new File(mFile));
mStreamID = mSoundPool.load(fileIS.getFD(), start, length, 0);
mPlayingStreamID = mSoundPool.play(mStreamID, 1f, 1f, 1, 0, 1f);
If I would use this, it works:
mStreamID = mSoundPool.load(mFile, 0);
mPlayingStreamID = mSoundPool.play(mStreamID, 1f, 1f, 1, 0, 1f);
Any ideas anyone?
Thanks
© Stack Overflow or respective owner