From 6b2167a4440f2c8b3f138b2a3df26310edb41d5a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 16 Jul 2006 16:52:29 +0000 Subject: audio: attempt to gracefully handle disconnected/reconnected devices Currently only ALSA is supported/tested, and only if the mixer device is not on the audio device being disconnected (software mixer). This patch allows me to disconnect my Headroom Total Airhead USB sound card, and resume playback (skips to the next song, which should be fixed) when the device is plugged back in. git-svn-id: https://svn.musicpd.org/mpd/trunk@4364 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/audio.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/audio.c') diff --git a/src/audio.c b/src/audio.c index 6766159b2..8180b290b 100644 --- a/src/audio.c +++ b/src/audio.c @@ -274,7 +274,7 @@ static void syncAudioDevicesEnabledArrays(void) { static int flushAudioBuffer() { int ret = -1; - int i; + int i, err; if(audioBufferPos == 0) return 0; @@ -286,11 +286,14 @@ static int flushAudioBuffer() { for(i = 0; i < audioOutputArraySize; i++) { if(!myAudioDevicesEnabled[i]) continue; - if(0 == playAudioOutput(audioOutputArray[i], audioBuffer, - audioBufferPos)) - { + err = playAudioOutput(audioOutputArray[i], audioBuffer, + audioBufferPos); + if (!err) ret = 0; - } + else if (err < 0) + /* device should already be closed if the play func + * returned an error */ + myAudioDevicesEnabled[i] = 0; } audioBufferPos = 0; -- cgit v1.2.3