stream now restores speaker after long freezes
This commit is contained in:
parent
011bdd8397
commit
cd657a1234
@ -103,14 +103,25 @@ void ALStream::update(double delta) {
|
||||
std::cout << "unqueue " << buffer << std::endl;
|
||||
}
|
||||
|
||||
uint preloaded = 0;
|
||||
if (!unusedBuffers.empty()) {
|
||||
uint buffer = unusedBuffers.front();
|
||||
if (preloadBuffer(buffer, loop)) {
|
||||
preloaded++;
|
||||
unusedBuffers.pop();
|
||||
std::cout << "queue " << buffer << std::endl;
|
||||
AL_CHECK(alSourceQueueBuffers(source, 1, &buffer));
|
||||
}
|
||||
}
|
||||
if (speaker->isStopped() && !speaker->isStoppedManually()) {
|
||||
std::cout << "preloaded " << preloaded << std::endl;
|
||||
if (preloaded) {
|
||||
speaker->play();
|
||||
std::cout << "speaker restored" << std::endl;
|
||||
} else {
|
||||
speaker->stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ALStream::setTime(duration_t time) {
|
||||
@ -160,6 +171,7 @@ void ALSpeaker::setLoop(bool loop) {
|
||||
}
|
||||
|
||||
void ALSpeaker::play() {
|
||||
stoppedManually = false;
|
||||
AL_CHECK(alSourcePlay(source));
|
||||
}
|
||||
|
||||
@ -168,9 +180,16 @@ void ALSpeaker::pause() {
|
||||
}
|
||||
|
||||
void ALSpeaker::stop() {
|
||||
AL_CHECK(alSourceStop(source));
|
||||
al->freeSource(source);
|
||||
source = 0;
|
||||
stoppedManually = true;
|
||||
if (source) {
|
||||
AL_CHECK(alSourceStop(source));
|
||||
al->freeSource(source);
|
||||
source = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool ALSpeaker::isStoppedManually() const {
|
||||
return stoppedManually;
|
||||
}
|
||||
|
||||
duration_t ALSpeaker::getTime() const {
|
||||
|
||||
@ -73,6 +73,7 @@ namespace audio {
|
||||
class ALSpeaker : public Speaker {
|
||||
ALAudio* al;
|
||||
int priority;
|
||||
bool stoppedManually = false;
|
||||
public:
|
||||
uint source;
|
||||
|
||||
@ -93,6 +94,7 @@ namespace audio {
|
||||
void play() override;
|
||||
void pause() override;
|
||||
void stop() override;
|
||||
bool isStoppedManually() const override;
|
||||
|
||||
duration_t getTime() const override;
|
||||
void setTime(duration_t time) override;
|
||||
|
||||
@ -294,7 +294,8 @@ void audio::update(double delta) {
|
||||
}
|
||||
|
||||
for (auto it = speakers.begin(); it != speakers.end();) {
|
||||
if (it->second->isStopped()) {
|
||||
if (it->second->isStoppedManually()) {
|
||||
streams.erase(it->first);
|
||||
it = speakers.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
|
||||
@ -205,6 +205,9 @@ namespace audio {
|
||||
|
||||
/// @brief Stop and destroy speaker
|
||||
virtual void stop() = 0;
|
||||
|
||||
/// @brief Check if the speaker has stopped by calling stop()
|
||||
virtual bool isStoppedManually() const = 0;
|
||||
|
||||
/// @brief Get current time position of playing audio
|
||||
/// @return time position in seconds
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user