From 3ce903fad86a4a9dfc3b77c412a4ff4134eccaa3 Mon Sep 17 00:00:00 2001 From: dvdsk Date: Thu, 5 Jun 2025 12:20:36 +0200 Subject: [PATCH 1/2] Make accidentally dropping OutputStream impossible This adds a drop bomb to OutputStream. Dropping a OutputStream will panic (unless we are dropping as part of unwinding). Technically OutputStream is now a run time enforced linear type. To get rid of a `OutputStream` you now have to call `OutputStream::close`. --- Cargo.lock | 163 +++++++++++++++++++++-------------------- Cargo.toml | 1 + examples/music_flac.rs | 1 + src/stream.rs | 22 +++++- 4 files changed, 104 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 101fb5a1..da4d2136 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,7 +18,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed7572b7ba83a31e20d1b48970ee402d2e3e0537dcfe0a3ff4d6eb7508617d43" dependencies = [ "alsa-sys", - "bitflags 2.9.0", + "bitflags 2.9.1", "cfg-if", "libc", ] @@ -35,9 +35,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "approx" @@ -74,21 +74,21 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] name = "bumpalo" -version = "3.17.0" +version = "3.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" +checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee" [[package]] name = "bytemuck" -version = "1.22.0" +version = "1.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6b1fc10dbac614ebc03540c9dbd60e83887fda27794998c6528f1782047d540" +checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" [[package]] name = "byteorder" @@ -104,9 +104,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "cc" -version = "1.2.18" +version = "1.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525046617d8376e3db1deffb079e91cef90a89fc3ca5c185bbf8c9ecdd15cd5c" +checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc" dependencies = [ "shlex", ] @@ -119,24 +119,24 @@ checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "clap" -version = "4.5.35" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8aa86934b44c19c50f87cc2790e19f54f7a67aedb64101c2e1a2e5ecfb73944" +checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.35" +version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2414dbb2dd0695280da6ea9261e327479e9d37b0630f6b53ba2a11c60c679fd9" +checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" dependencies = [ "anstyle", "clap_lex", @@ -145,9 +145,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "claxon" @@ -238,15 +238,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "objc2", ] [[package]] name = "divan" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "009c56317fe2bd3b5eebe3aa888828c62ed1b085d26c1ef2079a60369795765e" +checksum = "a405457ec78b8fe08b0e32b4a3570ab5dff6dd16eb9e76a5ee0a9d9cbd898933" dependencies = [ "cfg-if", "clap", @@ -258,15 +258,21 @@ dependencies = [ [[package]] name = "divan-macros" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4de9827ae754db91aedec0277381f5a2d8e2f801564c8d774acfe1ab1b045e" +checksum = "9556bc800956545d6420a640173e5ba7dfa82f38d3ea5a167eb555bc69ac3323" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "drop_bomb" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bda8e21c04aca2ae33ffc2fd8c23134f3cac46db123ba97bd9d3f3b8a4a85e1" + [[package]] name = "encoding_rs" version = "0.8.35" @@ -294,9 +300,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.11" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" +checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" dependencies = [ "libc", "windows-sys 0.59.0", @@ -405,20 +411,20 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi 0.11.1+wasi-snapshot-preview1", ] [[package]] name = "getrandom" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "libc", @@ -434,9 +440,9 @@ checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "hashbrown" -version = "0.15.2" +version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" [[package]] name = "hound" @@ -505,15 +511,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.171" +version = "0.2.173" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb" [[package]] name = "linux-raw-sys" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" [[package]] name = "log" @@ -532,9 +538,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "minimp3-sys" @@ -562,7 +568,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "jni-sys", "log", "ndk-sys", @@ -671,7 +677,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10cbe18d879e20a4aea544f8befe38bcf52255eb63d3f23eca2842f3319e4c07" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "libc", "objc2", "objc2-core-audio", @@ -698,7 +704,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0f1cc99bb07ad2ddb6527ddf83db6a15271bb036b3eb94b801cd44fdc666ee1" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "objc2", ] @@ -708,7 +714,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "dispatch2", "objc2", ] @@ -781,9 +787,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -827,13 +833,12 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" dependencies = [ "rand_chacha 0.9.0", "rand_core 0.9.3", - "zerocopy", ] [[package]] @@ -862,7 +867,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.2.16", ] [[package]] @@ -871,7 +876,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "getrandom 0.3.2", + "getrandom 0.3.3", ] [[package]] @@ -926,12 +931,13 @@ dependencies = [ "crossbeam-channel", "dasp_sample", "divan", + "drop_bomb", "hound", "lewton", "minimp3_fixed", "num-rational", "quickcheck", - "rand 0.9.0", + "rand 0.9.1", "rstest", "rstest_reuse", "symphonia", @@ -990,11 +996,11 @@ dependencies = [ [[package]] name = "rustix" -version = "1.0.5" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf" +checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", "errno", "libc", "linux-raw-sys", @@ -1003,9 +1009,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" +checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" [[package]] name = "same-file" @@ -1030,12 +1036,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "slab" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] +checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d" [[package]] name = "slice-ring-buffer" @@ -1219,9 +1222,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.100" +version = "2.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8" dependencies = [ "proc-macro2", "quote", @@ -1275,15 +1278,15 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "toml_datetime" -version = "0.6.8" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" [[package]] name = "toml_edit" -version = "0.22.24" +version = "0.22.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap", "toml_datetime", @@ -1303,9 +1306,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +checksum = "1b1ffbcf9c6f6b99d386e7444eb608ba646ae452a36b39737deb9663b610f662" dependencies = [ "proc-macro2", "quote", @@ -1314,9 +1317,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.33" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" dependencies = [ "once_cell", ] @@ -1339,9 +1342,9 @@ dependencies = [ [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" @@ -1634,9 +1637,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.7.4" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36" +checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd" dependencies = [ "memchr", ] @@ -1647,23 +1650,23 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" dependencies = [ - "bitflags 2.9.0", + "bitflags 2.9.1", ] [[package]] name = "zerocopy" -version = "0.8.24" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.24" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index a92f2984..f05de568 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ tracing = { version = "0.1.40", optional = true } atomic_float = { version = "1.1.0", optional = true } num-rational = "0.4.2" +drop_bomb = "0.1.5" [features] default = ["playback", "flac", "vorbis", "wav", "mp3"] diff --git a/examples/music_flac.rs b/examples/music_flac.rs index f93028be..bf712fb0 100644 --- a/examples/music_flac.rs +++ b/examples/music_flac.rs @@ -3,6 +3,7 @@ use std::error::Error; fn main() -> Result<(), Box> { let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?; let sink = rodio::Sink::connect_new(stream_handle.mixer()); + drop(stream_handle); let file = std::fs::File::open("assets/music.flac")?; sink.append(rodio::Decoder::try_from(file)?); diff --git a/src/stream.rs b/src/stream.rs index 4157a8ed..49375a66 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -11,22 +11,33 @@ use crate::mixer::{mixer, Mixer, MixerSource}; use crate::sink::Sink; use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::{BufferSize, Sample, SampleFormat, StreamConfig}; +use drop_bomb::DropBomb; use std::io::{Read, Seek}; use std::marker::Sync; use std::{error, fmt}; const HZ_44100: SampleRate = 44_100; -/// `cpal::Stream` container. -/// Use `mixer()` method to control output. -/// If this is dropped, playback will end, and the associated output stream will be disposed. +/// `cpal::Stream` container. Use `mixer()` method to control output. This +/// type **can not be dropped**. It will panic and crash your program if +/// dropped normally. Instead you must call [`OutputStream::close`]. +/// +/// # Panics +/// This will panic if dropped. Instead call [`OutputStream::close`] pub struct OutputStream { config: OutputStreamConfig, mixer: Mixer, _stream: cpal::Stream, + bomb: DropBomb, } impl OutputStream { + /// Closes the outputstream and drops it whithout panicking. This will + /// stop all audio playing through this `OutputStream`. + pub fn close(mut self) { + self.bomb.defuse(); + } + /// Access the output stream's mixer. pub fn mixer(&self) -> &Mixer { &self.mixer @@ -449,6 +460,11 @@ impl OutputStream { _stream: stream, mixer: controller, config: *config, + bomb: DropBomb::new( + "You can not drop an `OutputStream` you \ + must call `close` on it instead. \ + See the docs for `OutputStream` for more", + ), }) }) } From 60ada817bff6f84b2242e5a3a7c80dc689312807 Mon Sep 17 00:00:00 2001 From: dvdsk Date: Thu, 5 Jun 2025 12:43:01 +0200 Subject: [PATCH 2/2] adds stream_handle.close() to examples --- examples/automatic_gain_control.rs | 1 + examples/basic.rs | 1 + examples/callback_on_end.rs | 1 + examples/custom_config.rs | 1 + examples/distortion.rs | 1 + examples/distortion_mp3.rs | 1 + examples/distortion_wav.rs | 1 + examples/distortion_wav_alternate.rs | 1 + examples/error_callback.rs | 1 + examples/low_pass.rs | 1 + examples/mix_multiple_sources.rs | 1 + examples/music_flac.rs | 2 +- examples/music_m4a.rs | 1 + examples/music_mp3.rs | 1 + examples/music_ogg.rs | 1 + examples/music_wav.rs | 1 + examples/noise_generator.rs | 1 + examples/reverb.rs | 1 + examples/seek_mp3.rs | 1 + examples/signal_generator.rs | 1 + examples/spatial.rs | 1 + examples/stereo.rs | 1 + 22 files changed, 22 insertions(+), 1 deletion(-) diff --git a/examples/automatic_gain_control.rs b/examples/automatic_gain_control.rs index 884d046a..38016b4b 100644 --- a/examples/automatic_gain_control.rs +++ b/examples/automatic_gain_control.rs @@ -43,5 +43,6 @@ fn main() -> Result<(), Box> { // Keep the program running until the playback is complete. sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/basic.rs b/examples/basic.rs index 5628bd3b..25373516 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -48,5 +48,6 @@ fn main() -> Result<(), Box> { thread::sleep(Duration::from_millis(1500)); + stream_handle.close(); Ok(()) } diff --git a/examples/callback_on_end.rs b/examples/callback_on_end.rs index f367f7f4..74b94a03 100644 --- a/examples/callback_on_end.rs +++ b/examples/callback_on_end.rs @@ -34,5 +34,6 @@ fn main() -> Result<(), Box> { playlist_pos.load(Ordering::Relaxed) ); + stream_handle.close(); Ok(()) } diff --git a/examples/custom_config.rs b/examples/custom_config.rs index 4e1ff76a..41b59537 100644 --- a/examples/custom_config.rs +++ b/examples/custom_config.rs @@ -31,5 +31,6 @@ fn main() -> Result<(), Box> { println!("Beep..."); thread::sleep(Duration::from_millis(1500)); + stream_handle.close(); Ok(()) } diff --git a/examples/distortion.rs b/examples/distortion.rs index eae17bf7..8c894824 100644 --- a/examples/distortion.rs +++ b/examples/distortion.rs @@ -21,5 +21,6 @@ fn main() -> Result<(), Box> { thread::sleep(Duration::from_secs(3)); println!("Done."); + stream_handle.close(); Ok(()) } diff --git a/examples/distortion_mp3.rs b/examples/distortion_mp3.rs index 895c7647..3cd31218 100644 --- a/examples/distortion_mp3.rs +++ b/examples/distortion_mp3.rs @@ -13,5 +13,6 @@ fn main() -> Result<(), Box> { sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/distortion_wav.rs b/examples/distortion_wav.rs index 0955fd51..e7f0089c 100644 --- a/examples/distortion_wav.rs +++ b/examples/distortion_wav.rs @@ -13,5 +13,6 @@ fn main() -> Result<(), Box> { sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/distortion_wav_alternate.rs b/examples/distortion_wav_alternate.rs index 8d3f36b4..6de877c8 100644 --- a/examples/distortion_wav_alternate.rs +++ b/examples/distortion_wav_alternate.rs @@ -45,5 +45,6 @@ fn main() -> Result<(), Box> { // Wait for playback to finish sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/error_callback.rs b/examples/error_callback.rs index bb55ebdf..f1ff634e 100644 --- a/examples/error_callback.rs +++ b/examples/error_callback.rs @@ -37,5 +37,6 @@ fn main() -> Result<(), Box> { eprintln!("Error with stream {}", err); } + stream_handle.close(); Ok(()) } diff --git a/examples/low_pass.rs b/examples/low_pass.rs index ec343888..31cc98c9 100644 --- a/examples/low_pass.rs +++ b/examples/low_pass.rs @@ -14,5 +14,6 @@ fn main() -> Result<(), Box> { sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/mix_multiple_sources.rs b/examples/mix_multiple_sources.rs index 75109c8b..4740390e 100644 --- a/examples/mix_multiple_sources.rs +++ b/examples/mix_multiple_sources.rs @@ -37,5 +37,6 @@ fn main() -> Result<(), Box> { // Sleep the thread until sink is empty. sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/music_flac.rs b/examples/music_flac.rs index bf712fb0..8e988e3c 100644 --- a/examples/music_flac.rs +++ b/examples/music_flac.rs @@ -3,12 +3,12 @@ use std::error::Error; fn main() -> Result<(), Box> { let stream_handle = rodio::OutputStreamBuilder::open_default_stream()?; let sink = rodio::Sink::connect_new(stream_handle.mixer()); - drop(stream_handle); let file = std::fs::File::open("assets/music.flac")?; sink.append(rodio::Decoder::try_from(file)?); sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/music_m4a.rs b/examples/music_m4a.rs index ca7c4391..9e66b94c 100644 --- a/examples/music_m4a.rs +++ b/examples/music_m4a.rs @@ -9,5 +9,6 @@ fn main() -> Result<(), Box> { sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/music_mp3.rs b/examples/music_mp3.rs index bacc7309..b229ccf9 100644 --- a/examples/music_mp3.rs +++ b/examples/music_mp3.rs @@ -9,5 +9,6 @@ fn main() -> Result<(), Box> { sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/music_ogg.rs b/examples/music_ogg.rs index f44dfec0..e0821ece 100644 --- a/examples/music_ogg.rs +++ b/examples/music_ogg.rs @@ -9,5 +9,6 @@ fn main() -> Result<(), Box> { sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/music_wav.rs b/examples/music_wav.rs index ea50de38..f49f56f7 100644 --- a/examples/music_wav.rs +++ b/examples/music_wav.rs @@ -9,5 +9,6 @@ fn main() -> Result<(), Box> { sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/noise_generator.rs b/examples/noise_generator.rs index 03a8a5d5..5d9615b3 100644 --- a/examples/noise_generator.rs +++ b/examples/noise_generator.rs @@ -26,5 +26,6 @@ fn main() -> Result<(), Box> { thread::sleep(interval_duration); + stream_handle.close(); Ok(()) } diff --git a/examples/reverb.rs b/examples/reverb.rs index b8c04b52..84c6dba4 100644 --- a/examples/reverb.rs +++ b/examples/reverb.rs @@ -13,5 +13,6 @@ fn main() -> Result<(), Box> { sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/seek_mp3.rs b/examples/seek_mp3.rs index c27f5346..3ee2e802 100644 --- a/examples/seek_mp3.rs +++ b/examples/seek_mp3.rs @@ -20,5 +20,6 @@ fn main() -> Result<(), Box> { sink.try_seek(Duration::from_secs(5))?; println!("seek example ended"); + stream_handle.close(); Ok(()) } diff --git a/examples/signal_generator.rs b/examples/signal_generator.rs index 1ae4048e..8560b7a4 100644 --- a/examples/signal_generator.rs +++ b/examples/signal_generator.rs @@ -67,5 +67,6 @@ fn main() -> Result<(), Box> { thread::sleep(interval_duration); + stream_handle.close(); Ok(()) } diff --git a/examples/spatial.rs b/examples/spatial.rs index f1b97e44..ae7f4cc8 100644 --- a/examples/spatial.rs +++ b/examples/spatial.rs @@ -56,5 +56,6 @@ fn main() -> Result<(), Box> { } sink.sleep_until_end(); + stream_handle.close(); Ok(()) } diff --git a/examples/stereo.rs b/examples/stereo.rs index c86eef73..5c12f2a0 100644 --- a/examples/stereo.rs +++ b/examples/stereo.rs @@ -12,5 +12,6 @@ fn main() -> Result<(), Box> { sink.sleep_until_end(); + stream_handle.close(); Ok(()) }