paused current sound

This commit is contained in:
2025-08-27 17:30:32 +02:00
parent b5c151cc55
commit 9f4bfea241
2 changed files with 21 additions and 3 deletions

View File

@@ -266,6 +266,8 @@ impl Polymusic {
self.paused = !self.paused;
if !self.paused {
self.time_last_frame = Instant::now();
} else {
self.music.pause();
}
}

View File

@@ -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~~~~~~~~~~~~~~~~~~~~~~~~~~~~