From ce34d8e16db29c358e21337be985600cef8a5044 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 25 Jul 2024 16:27:31 +0200 Subject: Add AudioBackend::start_stream(). --- src/wx/audio_backend.cc | 19 +++++++++++++++++++ src/wx/audio_backend.h | 2 ++ src/wx/film_viewer.cc | 17 +++-------------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/wx/audio_backend.cc b/src/wx/audio_backend.cc index ae37ab851..351f0d78b 100644 --- a/src/wx/audio_backend.cc +++ b/src/wx/audio_backend.cc @@ -84,3 +84,22 @@ AudioBackend::abort_stream_if_running() } +optional +AudioBackend::start_stream() +{ +#if (RTAUDIO_VERSION_MAJOR >= 6) + if (_rtaudio.startStream() != RTAUDIO_NO_ERROR) { + return last_rtaudio_error(); + } +#else + try { + _rtaudio.startStream(); + } catch (RtAudioError& e) { + return string(e.what()); + } +#endif + + return {}; +} + + diff --git a/src/wx/audio_backend.h b/src/wx/audio_backend.h index 10646ebae..91e8ccab5 100644 --- a/src/wx/audio_backend.h +++ b/src/wx/audio_backend.h @@ -39,6 +39,8 @@ public: } void abort_stream_if_running(); + boost::optional start_stream(); + #if (RTAUDIO_VERSION_MAJOR >= 6) std::string last_rtaudio_error() const; #endif diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index 65e2afb56..1876aac74 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -353,25 +353,14 @@ FilmViewer::start_audio_stream_if_open () if (audio.isStreamOpen()) { audio.setStreamTime(_video_view->position().seconds()); -#if (RTAUDIO_VERSION_MAJOR >= 6) - if (audio.startStream() != RTAUDIO_NO_ERROR) { + auto error = AudioBackend::instance()->start_stream(); + if (error) { _audio_channels = 0; error_dialog( _video_view->get(), - _("There was a problem starting audio playback. Please try another audio output device in Preferences."), std_to_wx(audio.last_rtaudio_error()) - ); - } -#else - try { - audio.startStream (); - } catch (RtAudioError& e) { - _audio_channels = 0; - error_dialog ( - _video_view->get(), - _("There was a problem starting audio playback. Please try another audio output device in Preferences."), std_to_wx(e.what()) + _("There was a problem starting audio playback. Please try another audio output device in Preferences."), std_to_wx(*error) ); } -#endif } } -- cgit v1.2.3