Update state when buffers are processed so that we know when streams

end.  Added an isPlaying method to check state.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4125 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2006-05-18 20:55:45 +00:00
parent 9d84542e49
commit 8de54d537c
+21 -5
View File
@@ -78,6 +78,14 @@ public abstract class Stream
AL10.alSourcef(_sourceId, AL10.AL_PITCH, _pitch); AL10.alSourcef(_sourceId, AL10.AL_PITCH, _pitch);
} }
/**
* Determines whether this stream is currently playing.
*/
public boolean isPlaying ()
{
return _state == AL10.AL_PLAYING;
}
/** /**
* Starts playing this stream. * Starts playing this stream.
*/ */
@@ -87,7 +95,7 @@ public abstract class Stream
Log.warning("Tried to play stream already playing."); Log.warning("Tried to play stream already playing.");
return; return;
} }
if (_state == -1) { if (_state == AL10.AL_INITIAL) {
_qidx = _qlen = 0; _qidx = _qlen = 0;
queueBuffers(NUM_BUFFERS); queueBuffers(NUM_BUFFERS);
} }
@@ -186,7 +194,7 @@ public abstract class Stream
return; return;
} }
// find out how many buffers have been played // find out how many buffers have been played and unqueue them
int played = AL10.alGetSourcei(_sourceId, AL10.AL_BUFFERS_PROCESSED); int played = AL10.alGetSourcei(_sourceId, AL10.AL_BUFFERS_PROCESSED);
if (played == 0) { if (played == 0) {
return; return;
@@ -199,7 +207,16 @@ public abstract class Stream
} }
_nbuf.flip(); _nbuf.flip();
AL10.alSourceUnqueueBuffers(_sourceId, _nbuf); AL10.alSourceUnqueueBuffers(_sourceId, _nbuf);
// enqueue up to the number of buffers played
queueBuffers(played); queueBuffers(played);
// find out if we're still playing; if not and we have buffers queued,
// we must restart
_state = AL10.alGetSourcei(_sourceId, AL10.AL_SOURCE_STATE);
if (_qlen > 0 && _state != AL10.AL_PLAYING) {
play();
}
} }
/** /**
@@ -319,9 +336,8 @@ public abstract class Stream
/** The buffer used to store audio data temporarily. */ /** The buffer used to store audio data temporarily. */
protected ByteBuffer _abuf; protected ByteBuffer _abuf;
/** The OpenAL state of the stream (AL_STOPPED, AL_PLAYING, AL_PAUSED, or /** The OpenAL state of the stream. */
* -1 if uninitialized). */ protected int _state = AL10.AL_INITIAL;
protected int _state = -1;
/** The size of the buffers in bytes. */ /** The size of the buffers in bytes. */
protected static final int BUFFER_SIZE = 131072; protected static final int BUFFER_SIZE = 131072;