|
@@ -23,6 +23,7 @@ pub struct AudioState {
|
|
current_song: Mutex<Option<Song>>,
|
|
current_song: Mutex<Option<Song>>,
|
|
track_handle: Mutex<Option<TrackHandle>>,
|
|
track_handle: Mutex<Option<TrackHandle>>,
|
|
is_looping: Mutex<bool>,
|
|
is_looping: Mutex<bool>,
|
|
|
|
+ volume: Mutex<f32>,
|
|
|
|
|
|
channel_id: Mutex<ChannelId>,
|
|
channel_id: Mutex<ChannelId>,
|
|
http: Mutex<Arc<Http>>,
|
|
http: Mutex<Arc<Http>>,
|
|
@@ -36,6 +37,7 @@ impl AudioState {
|
|
current_song: Mutex::new(None),
|
|
current_song: Mutex::new(None),
|
|
track_handle: Mutex::new(None),
|
|
track_handle: Mutex::new(None),
|
|
is_looping: Mutex::new(false),
|
|
is_looping: Mutex::new(false),
|
|
|
|
+ volume: Mutex::new(1.0),
|
|
|
|
|
|
channel_id: Mutex::new(msg.channel_id),
|
|
channel_id: Mutex::new(msg.channel_id),
|
|
http: Mutex::new(ctx.http.clone()),
|
|
http: Mutex::new(ctx.http.clone()),
|
|
@@ -101,8 +103,12 @@ impl AudioState {
|
|
let source = input::Input::float_pcm(true, reader);
|
|
let source = input::Input::float_pcm(true, reader);
|
|
|
|
|
|
let mut handler = audio_state.handler.lock().await;
|
|
let mut handler = audio_state.handler.lock().await;
|
|
|
|
+ let volume = audio_state.volume.lock().await;
|
|
|
|
|
|
let handle = handler.play_source(source);
|
|
let handle = handler.play_source(source);
|
|
|
|
+ if let Err(e) = handle.set_volume(*volume) {
|
|
|
|
+ println!("{}", e);
|
|
|
|
+ }
|
|
|
|
|
|
if let Err(why) = handle.add_event(
|
|
if let Err(why) = handle.add_event(
|
|
Event::Track(TrackEvent::End),
|
|
Event::Track(TrackEvent::End),
|
|
@@ -178,6 +184,17 @@ impl AudioState {
|
|
Ok(*is_looping)
|
|
Ok(*is_looping)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ pub async fn set_volume(audio_state: Arc<AudioState>, new_volume: f32) -> Result<(), String> {
|
|
|
|
+ let mut track_handle = audio_state.track_handle.lock().await;
|
|
|
|
+ let mut volume = audio_state.volume.lock().await;
|
|
|
|
+
|
|
|
|
+ *volume = new_volume / 100.0;
|
|
|
|
+
|
|
|
|
+ track_handle.as_mut().map(move |handle| handle.set_volume(*volume));
|
|
|
|
+
|
|
|
|
+ Ok(())
|
|
|
|
+ }
|
|
|
|
+
|
|
pub async fn get_string(audio_state: Arc<AudioState>) -> String {
|
|
pub async fn get_string(audio_state: Arc<AudioState>) -> String {
|
|
let current_song = audio_state.current_song.lock().await;
|
|
let current_song = audio_state.current_song.lock().await;
|
|
let current_song = match &*current_song {
|
|
let current_song = match &*current_song {
|