paused current sound
This commit is contained in:
@@ -266,6 +266,8 @@ impl Polymusic {
|
||||
self.paused = !self.paused;
|
||||
if !self.paused {
|
||||
self.time_last_frame = Instant::now();
|
||||
} else {
|
||||
self.music.pause();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
src/music.rs
18
src/music.rs
@@ -3,6 +3,7 @@ use crate::polygon_draw::*;
|
||||
use crate::utils::string_to_polygon;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use kira::sound::SoundData;
|
||||
use kira::{AudioManager, sound::static_sound::StaticSoundData};
|
||||
|
||||
use iced::event::Status;
|
||||
@@ -33,6 +34,9 @@ pub struct Music {
|
||||
pub current_delta: f32,
|
||||
#[serde(skip)]
|
||||
point_removed: Vec<(f32, PolygonFrame)>,
|
||||
|
||||
#[serde(skip)]
|
||||
handles_audio: Vec<<StaticSoundData as SoundData>::Handle>,
|
||||
}
|
||||
|
||||
impl Music {
|
||||
@@ -80,6 +84,7 @@ impl Music {
|
||||
teta: 0.,
|
||||
current_delta: 0.,
|
||||
point_removed: vec![],
|
||||
handles_audio: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,11 +109,22 @@ impl Music {
|
||||
|
||||
current_frame.teta = currrent_teta;
|
||||
let sound_to_play = current_frame.all_sound_to_play_btw(teta_temp, current_frame.teta);
|
||||
let mut handles: Vec<<StaticSoundData as SoundData>::Handle> = vec![];
|
||||
for sound in sound_to_play {
|
||||
handles.push(
|
||||
audio_manager
|
||||
.play(sound.clone())
|
||||
.expect("Error to play sound");
|
||||
.expect("Error to play sound"),
|
||||
);
|
||||
}
|
||||
self.handles_audio.append(&mut handles);
|
||||
}
|
||||
|
||||
pub fn pause(&mut self) {
|
||||
for h in &mut self.handles_audio {
|
||||
h.stop(kira::Tween::default());
|
||||
}
|
||||
self.handles_audio = vec![];
|
||||
}
|
||||
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SET~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Reference in New Issue
Block a user