- Keep the current/desired state of the sound up to date and add a method to check if a sound is

pending, (ie. set to play but hasn't finished buffering)


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1160 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mark Johnson
2011-04-14 20:33:28 +00:00
parent ea2f7976a4
commit 81abfe0d30
+15 -5
View File
@@ -265,10 +265,9 @@ public class Sound
*/ */
public void pause () public void pause ()
{ {
_stateDesired = AL10.AL_PAUSED;
if (_source != null) { if (_source != null) {
_source.pause(); _source.pause();
} else {
_stateDesired = AL10.AL_PAUSED;
} }
} }
@@ -278,10 +277,9 @@ public class Sound
*/ */
public void stop () public void stop ()
{ {
_stateDesired = AL10.AL_STOPPED;
if (_source != null) { if (_source != null) {
_source.stop(); _source.stop();
} else {
_stateDesired = AL10.AL_STOPPED;
} }
} }
@@ -293,6 +291,14 @@ public class Sound
return _source != null && _source.isPlaying(); return _source != null && _source.isPlaying();
} }
/**
* Called to check if this sound wants to start playing.
*/
public boolean isPending ()
{
return _stateDesired == AL10.AL_PLAYING;
}
protected Sound (SoundGroup group, ClipBuffer buffer) protected Sound (SoundGroup group, ClipBuffer buffer)
{ {
_group = group; _group = group;
@@ -306,6 +312,7 @@ public class Sound
if (obs != null) { if (obs != null) {
obs.soundStarted(null); obs.soundStarted(null);
} }
_stateDesired = AL10.AL_INVALID;
return false; return false;
} }
@@ -332,6 +339,7 @@ public class Sound
// left hanging // left hanging
if (obs != null && _stateDesired != AL10.AL_STOPPED) { if (obs != null && _stateDesired != AL10.AL_STOPPED) {
obs.soundStarted(Sound.this); obs.soundStarted(Sound.this);
_stateDesired = AL10.AL_INVALID;
} }
} }
}); });
@@ -341,6 +349,7 @@ public class Sound
if (obs != null) { if (obs != null) {
obs.soundStarted(null); obs.soundStarted(null);
} }
_stateDesired = AL10.AL_INVALID;
return false; return false;
} }
} }
@@ -354,6 +363,7 @@ public class Sound
if (_source == null) { if (_source == null) {
_source = _group.acquireSource(this); _source = _group.acquireSource(this);
if (_source == null) { if (_source == null) {
_stateDesired = AL10.AL_INVALID;
return false; return false;
} }
@@ -424,7 +434,7 @@ public class Sound
protected Source _source; protected Source _source;
/** The desired state of the sound (stopped, playing, paused) after resolution. */ /** The desired state of the sound (stopped, playing, paused) after resolution. */
protected int _stateDesired; protected int _stateDesired = AL10.AL_INVALID;
/** Whether or not looping is desired after resolution. */ /** Whether or not looping is desired after resolution. */
protected boolean _loopDesired; protected boolean _loopDesired;