Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
embed audio files as bytes
Brendan Allan2efc0fdf7218
diff --git a/apps/desktop/src-tauri/src/audio.rs b/apps/desktop/src-tauri/src/audio.rsindex ee48462f3..80b5ef0f8 100644--- a/apps/desktop/src-tauri/src/audio.rs+++ b/apps/desktop/src-tauri/src/audio.rs@@ -269,3 +269,16 @@ pub async fn start_capturing((capture, rx.await.unwrap())}++pub fn play_audio<const N: usize>(bytes: &'static [u8; N]) {+ use rodio::{Decoder, OutputStream, Sink};+ use std::io::Cursor;++ if let Ok((_, stream)) = OutputStream::try_default() {+ let file = Cursor::new(bytes);+ let source = Decoder::new(file).unwrap();+ let sink = Sink::try_new(&stream).unwrap();+ sink.append(source);+ sink.sleep_until_end();+ }+}diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex 8a42fef9c..d4b4c9b0f 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -25,7 +25,6 @@ use num_traits::ToBytes;use objc2_app_kit::NSScreenSaverWindowLevel;use project_recordings::ProjectRecordings;use recording::{DisplaySource, InProgressRecording};-use rodio::{Decoder, OutputStream, Sink};use serde::{Deserialize, Serialize};use serde_json::json;use specta::Type;@@ -266,13 +265,7 @@ async fn start_recording(app: AppHandle, state: MutableState<'_, App>) -> Resultwindow.eval("window.location.reload()").unwrap();window.show().unwrap();- if let Ok((_, stream)) = OutputStream::try_default() {- let file = std::fs::File::open("sounds/start-recording.ogg").unwrap();- let source = Decoder::new(BufReader::new(file)).unwrap();- let sink = Sink::try_new(&stream).unwrap();- sink.append(source);- sink.sleep_until_end();- }+ audio::play_audio(include_bytes!("../sounds/start-recording.ogg"));RecordingStarted.emit(&app).ok();@@ -376,13 +369,7 @@ async fn stop_recording(app: AppHandle, state: MutableState<'_, App>) -> Result<.emit(&app).ok();- if let Ok((_, stream)) = OutputStream::try_default() {- let file = std::fs::File::open("sounds/stop-recording.ogg").unwrap();- let source = Decoder::new(BufReader::new(file)).unwrap();- let sink = Sink::try_new(&stream).unwrap();- sink.append(source);- sink.sleep_until_end();- }+ audio::play_audio(include_bytes!("../sounds/stop-recording.ogg"));Ok(())}