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