-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unwrap and expect from example code
- Loading branch information
Showing
15 changed files
with
100 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let stream_handle = | ||
rodio::OutputStreamBuilder::try_default_stream().expect("open default audio stream"); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::try_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.flac").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.flac")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let stream_handle = | ||
rodio::OutputStreamBuilder::try_default_stream().expect("open default audio stream"); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::try_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.m4a").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.m4a")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let stream_handle = | ||
rodio::OutputStreamBuilder::try_default_stream().expect("open default audio stream"); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::try_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.mp3").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.mp3")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let stream_handle = | ||
rodio::OutputStreamBuilder::try_default_stream().expect("open default audio stream"); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::try_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.ogg").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.ogg")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let stream_handle = | ||
rodio::OutputStreamBuilder::try_default_stream().expect("open default audio stream"); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::try_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.wav").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.wav")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
use rodio::Source; | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
use std::time::Duration; | ||
|
||
fn main() { | ||
let stream_handle = | ||
rodio::OutputStreamBuilder::try_default_stream().expect("open default audio stream"); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::try_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.ogg").unwrap(); | ||
let source = rodio::Decoder::new(BufReader::new(file)).unwrap(); | ||
let file = std::fs::File::open("assets/music.ogg")?; | ||
let source = rodio::Decoder::new(BufReader::new(file))?; | ||
let with_reverb = source.buffered().reverb(Duration::from_millis(40), 0.7); | ||
sink.append(with_reverb); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
use std::time::Duration; | ||
|
||
fn main() { | ||
let stream_handle = | ||
rodio::OutputStreamBuilder::try_default_stream().expect("open default audio stream"); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::try_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/music.mp3").unwrap(); | ||
sink.append(rodio::Decoder::new(BufReader::new(file)).unwrap()); | ||
let file = std::fs::File::open("assets/music.mp3")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?); | ||
|
||
std::thread::sleep(std::time::Duration::from_secs(2)); | ||
sink.try_seek(Duration::from_secs(0)).unwrap(); | ||
sink.try_seek(Duration::from_secs(0))?; | ||
|
||
std::thread::sleep(std::time::Duration::from_secs(2)); | ||
sink.try_seek(Duration::from_secs(4)).unwrap(); | ||
sink.try_seek(Duration::from_secs(4))?; | ||
|
||
sink.sleep_until_end(); | ||
|
||
// This doesn't do anything since the sound has ended already. | ||
sink.try_seek(Duration::from_secs(5)).unwrap(); | ||
sink.try_seek(Duration::from_secs(5))?; | ||
println!("seek example ended"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
//! Plays a tone alternating between right and left ears, with right being first. | ||
|
||
use rodio::Source; | ||
use std::error::Error; | ||
use std::io::BufReader; | ||
|
||
fn main() { | ||
let stream_handle = | ||
rodio::OutputStreamBuilder::try_default_stream().expect("open default audio stream"); | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
let stream_handle = rodio::OutputStreamBuilder::try_default_stream()?; | ||
let sink = rodio::Sink::connect_new(&stream_handle.mixer()); | ||
|
||
let file = std::fs::File::open("assets/RL.ogg").unwrap(); | ||
sink.append( | ||
rodio::Decoder::new(BufReader::new(file)) | ||
.unwrap() | ||
.amplify(0.2), | ||
); | ||
let file = std::fs::File::open("assets/RL.ogg")?; | ||
sink.append(rodio::Decoder::new(BufReader::new(file))?.amplify(0.2)); | ||
|
||
sink.sleep_until_end(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters