summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-07-25 16:27:31 +0200
committerCarl Hetherington <cth@carlh.net>2024-07-26 11:39:59 +0200
commitce34d8e16db29c358e21337be985600cef8a5044 (patch)
tree67b757bfbe592b94e694c21293b19dd716004867
parent85ddc6ae876810b618e632365c89d06ad60f8b3b (diff)
Add AudioBackend::start_stream().
-rw-r--r--src/wx/audio_backend.cc19
-rw-r--r--src/wx/audio_backend.h2
-rw-r--r--src/wx/film_viewer.cc17
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<string>
+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<std::string> 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
}
}