diff --git a/source/Client.cpp b/source/Client.cpp index 36f22c6..6d36252 100644 --- a/source/Client.cpp +++ b/source/Client.cpp @@ -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(),