Add AudioBackend::start_stream().
authorCarl Hetherington <cth@carlh.net>
Thu, 25 Jul 2024 14:27:31 +0000 (16:27 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 26 Jul 2024 09:39:59 +0000 (11:39 +0200)
src/wx/audio_backend.cc
src/wx/audio_backend.h
src/wx/film_viewer.cc

index ae37ab8519ac00e4d3837f70609e14486f18fc0f..351f0d78b090b8de5a4aeb4354ae83cf17fed49d 100644 (file)
@@ -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 {};
+}
+
+
index 10646ebae8591c9c58ce1584740c8103f1e95165..91e8ccab56d970c22e76c1ce5f889e2edf9eef60 100644 (file)
@@ -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
index 65e2afb56adc509f1e63bb4984e9a74c342b66b1..1876aac74829687eb405fb11c74059300914e18b 100644 (file)
@@ -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
        }
 }