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 us开发者_Go百科e this, it works:
mStreamID = mSoundPool.load(mFile, 0);
mPlayingStreamID = mSoundPool.play(mStreamID, 1f, 1f, 1, 0, 1f);
Any ideas anyone?
Thanks
Perhaps you already figured this out, but reading the documentation it seems that length is probably in bytes, not milliseconds. It states that passing a file descriptor is useful if you store multiple sounds in a single binary file. This implies that you are telling the system which sound of the multiples to pull out, but I think it has to be able to process it as a single sound. So this is used if you concatenate several wave files together, and want to tell it to play a single wave file from the binary.
精彩评论