fredsa / playn

Cross platform game library for N≥4 platforms
0 stars 1 forks source link

isPlaying() returns false #137

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using the assetManager to play music like this:

assetManager().getSound(music).play()

but before I start it I want to make sure the music isn't already playing:

if (!assetManager().getSound(music).isPlaying()) {

this works great in HTML but on android the isPlaying always returns false

Am I using the assetManger in a wrong way? Or is this a bug? 
I've solved it by changing playn.android.AndroidAudio to check if is already 
has a AndroidSound and not create a new one every time.

Cheers,
     Erik Jan

Original issue reported on code.google.com by erikjan....@gmail.com on 16 Feb 2012 at 7:46

GoogleCodeExporter commented 9 years ago
Patches welcome.

Original comment by fredsa@google.com on 16 Feb 2012 at 5:50

GoogleCodeExporter commented 9 years ago
Hi,

Here is my patch, I've solved it by adding a path attribute to the Android 
Sound so that we can return the sound if it was already loaded by the 
MediaPlayer in AndroidAudio. Don't know if you like this, but can easily change 
it as long as we don't return a new object on every call in AndroidAudio.

Keep up the good work!

Cheers,
        Erik Jan 

Original comment by erikjan....@gmail.com on 16 Feb 2012 at 7:35

Attachments:

GoogleCodeExporter commented 9 years ago
Erik Jan,

I think the AndroidAudio getSound() method name was probably misleading. I went 
ahead and renamed the method to be createSound(), consistent with the other 
backends.

http://code.google.com/p/playn/source/detail?r=fe321caab3a600e704eb2ab339524c3b5
015ecb2

Note, it's intentional that multiple calls to Assets#getSound() with the same 
path will return multiple unique Sound instances, which each will have a 
separate isPlaying() state. This allows you to have multiple channels playing 
the same sound effect simultaneous (but with different start/end times).

Original comment by fredsa@google.com on 23 Feb 2012 at 9:59