MCPcopy Create free account
hub / github.com/RustOtomeLab/RustEng / play_loop

Method play_loop

src/media/player.rs:69–92  ·  view source on GitHub ↗
(&self, path: &str, volume: f32)

Source from the content-addressed store, hash-verified

67 })
68 }
69
70 pub(crate) fn play_loop(&self, path: &str, volume: f32) -> Result<(), MediaError> {
71 if let Some(s) = self.sink.borrow_mut().take() {
72 s.stop();
73 }
74
75 let file = File::open(path).map_err(|e| MediaError::OpenFile {
76 path: path.to_string(),
77 source: e,
78 })?;
79 let source = Decoder::new(BufReader::new(file))
80 .map_err(|e| MediaError::DecodeAudio {
81 path: path.to_string(),
82 source: e,
83 })?
84 .repeat_infinite();
85
86 let sink = Sink::try_new(&self.stream_handle)?;
87 sink.append(source);
88 sink.set_volume(volume);
89 sink.play();
90
91 *self.sink.borrow_mut() = Some(sink);
92 Ok(())
93 }
94
95 pub(crate) fn stop(&self) {

Callers 1

play_bgmMethod · 0.80

Calls 2

playMethod · 0.80
stopMethod · 0.45

Tested by

no test coverage detected