From 7d2fa5b1bcce7351b81b2d0d927e61035c2224d9 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Wed, 11 Nov 2009 19:50:04 +0100 Subject: Print message and stop playback when hitting libao error Thanks to jpfuentes2@github --- src/player.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/player.c') diff --git a/src/player.c b/src/player.c index bb65ee0..ef3cd19 100644 --- a/src/player.c +++ b/src/player.c @@ -197,8 +197,11 @@ static char BarPlayerAACCb (void *ptr, size_t size, void *stream) { format.channels = player->channels; format.rate = player->samplerate; format.byte_format = AO_FMT_LITTLE; - player->audioOutDevice = ao_open_live (audioOutDriver, - &format, NULL); + if ((player->audioOutDevice = ao_open_live (audioOutDriver, + &format, NULL)) == NULL) { + BarUiMsg (MSG_ERR, "Cannot open audio device\n"); + return 0; + } player->mode = PLAYER_AUDIO_INITIALIZED; break; } @@ -351,8 +354,11 @@ static char BarPlayerMp3Cb (void *ptr, size_t size, void *stream) { format.channels = player->channels; format.rate = player->samplerate; format.byte_format = AO_FMT_LITTLE; - player->audioOutDevice = ao_open_live (audioOutDriver, - &format, NULL); + if ((player->audioOutDevice = ao_open_live (audioOutDriver, + &format, NULL)) == NULL) { + BarUiMsg (MSG_ERR, "Cannot open audio device\n"); + return 0; + } /* calc song length using the framerate of the first decoded frame */ player->songDuration = (float) player->waith.contentLength / @@ -394,6 +400,7 @@ static char BarPlayerMp3Cb (void *ptr, size_t size, void *stream) { void *BarPlayerThread (void *data) { struct audioPlayer *player = data; char extraHeaders[25]; + void *ret = NULL; #ifdef ENABLE_FAAD NeAACDecConfigurationPtr conf; #endif @@ -468,6 +475,9 @@ void *BarPlayerThread (void *data) { /* this should never happen: thread is aborted above */ break; } + if (player->audioOutDevice == NULL && wRet == WAITRESS_RET_CB_ABORT) { + ret = (void *) 0x1; + } ao_close(player->audioOutDevice); WaitressFree (&player->waith); #ifdef ENABLE_FAAD @@ -479,5 +489,7 @@ void *BarPlayerThread (void *data) { player->mode = PLAYER_FINISHED_PLAYBACK; - return NULL; + /* return NULL == everything's fine, everything else: hard error, stop + * playback */ + return ret; } -- cgit v1.2.3