Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

android - Soundpool plays only first 5 secs of file. Why?

I use Soundpool in my app, so far it works good, but I do have a wav file which is 10 secs. Unfortunately, soundpool plays only the first 5 secs. How to make soundpool to play the whole track? I have converted wav to -- ogg and mp3 still the same issue. It plays only the first 5 secs. Any help would be much appreciated.

//set up audio player
mSoundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
//load fx
mSoundPoolMap.put(RAW_1_1, mSoundPool.load(this, R.raw.loop1, 1));
//playing soundpool
case R.id.button1:          
mSoundPool.stop(mStream1);
mStream1= mSoundPool.play(mSoundPoolMap.get(RAW_1_1), streamVolume, streamVolume, 1, LOOP_1_TIME, 1f);

UPD Last: Maybe someone will find it here and read it. Seems soundpool cant play more then 5 secs. It is his maximum, for more longer sounds use MediaPlayer. I hope you will not spend so much of your time like i did)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

So I think you reached the 1M limit in SoundPool.

SoundPool is hard code the buffer size as 1M, for all loaded file, store in pcm format.

So it do not care of ogg or wav.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...