Procházet zdrojové kódy

WIP: Only remove song once it has been played

Frans Bergman před 1 rokem
rodič
revize
55e4e91415
2 změnil soubory, kde provedl 14 přidání a 2 odebrání
  1. 6 2
      src/audio/audio_state.rs
  2. 8 0
      src/audio/song_queue.rs

+ 6 - 2
src/audio/audio_state.rs

@@ -71,12 +71,12 @@ impl AudioState {
 
     async fn play_audio(audio_state: Arc<AudioState>) {
         let is_looping = audio_state.is_looping.lock().await;
-        let mut queue = audio_state.queue.lock().await;
+        let queue = audio_state.queue.lock().await;
         let song = if *is_looping {
             let mut current_song = audio_state.current_song.lock().await;
             current_song.take()
         } else {
-            queue.pop()
+            queue.peek()
         };
         drop(is_looping);
 
@@ -217,6 +217,10 @@ struct SongEndNotifier {
 #[async_trait]
 impl VoiceEventHandler for SongEndNotifier {
     async fn act(&self, _ctx: &EventContext<'_>) -> Option<Event> {
+        {
+            let mut queue = self.audio_state.queue.lock().await;
+            queue.pop();
+        }
         AudioState::play_audio(self.audio_state.clone()).await;
 
         None

+ 8 - 0
src/audio/song_queue.rs

@@ -32,6 +32,14 @@ impl SongQueue {
             deque.push_back(song);
         }
     }
+    pub fn peek(&self) -> Option<Song> {
+        let user = match self.users.front() {
+            Some(user) => user,
+            None => return None,
+        };
+        let deque = self.queues.get(&user).unwrap();
+        deque.front().cloned()
+    }
     pub fn pop(&mut self) -> Option<Song> {
         let user = match self.users.pop_front() {
             Some(user) => user,