hushaojie04 / libgdx

Automatically exported from code.google.com/p/libgdx
0 stars 0 forks source link

sound.play() and then .setLooping() doesn't loop on Android, but sound.loop() does #855

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Similar to http://code.google.com/p/libgdx/issues/detail?id=552

Plays, loops, works:
 sound.loop();

Plays only once on Android and outputs an error (works on Desktop):
 long soundId = sound.play();
 sound.setLooping(soundId, true);

Error:
E/AudioTrack(8917): setLoop invalid value: loopStart 0, loopEnd 13278, 
loopCount -1, framecount 3904, user 3904

Original issue reported on code.google.com by code6...@gmail.com on 21 May 2012 at 12:45

GoogleCodeExporter commented 9 years ago
I can not reproduce this issue? Which version are you using?

Two known problems with Sound:
- samples can not be bigger than 1mb when uncompressed from the storage format 
(mp3, ogg). Nothing we can do about that, it's a system limitation.
- samples take some time to load asynchronously due to the way Android's 
SoundPool works. If you load and play immediately, chances are that the first 
play will fail with "sample X is not READY". Again, there's not a lot we can do 
about.

Original comment by badlogicgames on 24 May 2012 at 11:04

GoogleCodeExporter commented 9 years ago
I am using libgdx-nightly-20120521, but this also happened in the latest stable 
(0.9.3). The file I'm trying to loop is a wav. It's this wav: 
https://bitbucket.org/code6/multiplayerspacegame/src/f50c56b61e65/MultiplayerSpa
ceGame/data/accel.wav

I just tested again, and I'm getting the same result as above. In fact, if you 
want to see this yourself, the game I'm working on is open source: 
https://bitbucket.org/code6/multiplayerspacegame

If you replace line 27 in 
https://bitbucket.org/code6/multiplayerspacegame/src/f50c56b61e65/MultiplayerSpa
ceGame/src/com/puchisoft/multiplayerspacegame/GameSounds.java
with "long soundId = sound.play(); sound.setLooping(soundId, true);", it will 
continue to loop properly on desktop, but on Android, it will only play once. 

The sound is played in game when you accelerate (Tap "Host", and then W key on 
Desktop, or dragging on Android to accelerate).

Not a big deal. I actually prefer the .loop(), but some tutorial didn't point 
it out, so it took me a bit to find this workaround. Thanks for the response!

Original comment by code6...@gmail.com on 25 May 2012 at 3:42