mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
Add simpler sound
This commit is contained in:
parent
9022308c54
commit
7abe65ea1c
5 changed files with 7 additions and 6 deletions
|
@ -3,11 +3,10 @@
|
|||
|
||||
use chrono::{Datelike, Local, Timelike};
|
||||
use kira::{
|
||||
AudioManager, AudioManagerSettings, DefaultBackend,
|
||||
sound::static_sound::StaticSoundData,
|
||||
sound::static_sound::StaticSoundData, AudioManager, AudioManagerSettings, DefaultBackend,
|
||||
};
|
||||
use std::io::Cursor;
|
||||
use slint::{Timer, TimerMode};
|
||||
use std::io::Cursor;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
@ -30,7 +29,7 @@ pub fn main() {
|
|||
let app = AppWindow::new().expect("AppWindow::new() failed");
|
||||
let app_weak = app.as_weak();
|
||||
|
||||
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default()).unwrap();
|
||||
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default()).unwrap();
|
||||
|
||||
let api = app.global::<Api>();
|
||||
api.on_play_sound(move |sound| {
|
||||
|
@ -41,7 +40,7 @@ pub fn main() {
|
|||
let sound_data = StaticSoundData::from_cursor(cursor).unwrap();
|
||||
let _sound_handle = manager.play(sound_data).unwrap();
|
||||
});
|
||||
|
||||
|
||||
let timer = Timer::default();
|
||||
timer.start(TimerMode::Repeated, std::time::Duration::from_millis(1000), move || {
|
||||
if let Some(app) = app_weak.upgrade() {
|
||||
|
|
|
@ -20,7 +20,7 @@ export component Dial {
|
|||
property <bool> moving: ta.firstTouch;
|
||||
in-out property <angle> dialAngle: DialState.startAngle;
|
||||
out property <int> volume: ((dialAngle - DialState.startAngle) / DialState.degreesFilledWithLights) * DialState.totalLights;
|
||||
changed volume => {
|
||||
changed volume => {
|
||||
Api.play-sound(SoundEffect.dial-tick);
|
||||
}
|
||||
|
||||
|
|
BIN
demos/home-automation/ui/sounds/bubblepopping.mp3
Normal file
BIN
demos/home-automation/ui/sounds/bubblepopping.mp3
Normal file
Binary file not shown.
|
@ -0,0 +1,2 @@
|
|||
SPDX-FileCopyrightText: BubblePopping by Sess8it -- https://freesound.org/s/762781/ -- License: Creative Commons 0
|
||||
SPDX-License-Identifier: CC0-1.0
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue