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

Callers 1

play_bgmMethod · 0.80

Calls 2

playMethod · 0.80
stopMethod · 0.45

Tested by

no test coverage detected