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:
faraphel 2024-10-22 12:04:05 +02:00
parent 73be1f9a80
commit 33033b0c96

View file

@ -133,9 +133,16 @@ void Client::loopPlayer() {
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(
this->stream,
audioPacket.content.data(),