added a small fix : if a new audio shall be played now, immediately stop the previous audio and play the new one instead
This commit is contained in:
parent
73be1f9a80
commit
33033b0c96
1 changed files with 9 additions and 2 deletions
|
@ -133,9 +133,16 @@ void Client::loopPlayer() {
|
||||||
|
|
||||||
std::cout << "[Client] Playing: " << audioPacket.timePlay << std::endl;
|
std::cout << "[Client] Playing: " << audioPacket.timePlay << std::endl;
|
||||||
|
|
||||||
std::cout << "playing: " << audioPacket.timePlay << std::endl;
|
// immediately stop playing music
|
||||||
|
// this avoids an offset created if this client's clock is too ahead of the others
|
||||||
|
// don't handle errors since audio might not be playing before
|
||||||
|
Pa_AbortStream(this->stream);
|
||||||
|
|
||||||
// play the audio buffer
|
// play the new audio data
|
||||||
|
if (const int error = Pa_StartStream(this->stream) != paNoError)
|
||||||
|
throw std::runtime_error("[Client] Could not start the PortAudio stream: " + std::string(Pa_GetErrorText(error)));
|
||||||
|
|
||||||
|
// write the new audio data into the audio buffer
|
||||||
const int error = Pa_WriteStream(
|
const int error = Pa_WriteStream(
|
||||||
this->stream,
|
this->stream,
|
||||||
audioPacket.content.data(),
|
audioPacket.content.data(),
|
||||||
|
|
Loading…
Reference in a new issue