From 63da8989a4fb95f6f910c662de9c76ce61bd9f33 Mon Sep 17 00:00:00 2001 From: supertick Date: Fri, 26 Apr 2024 12:24:00 -0700 Subject: [PATCH 1/3] quick audio file fixes --- .../org/myrobotlab/audio/PlaylistPlayer.java | 5 +++++ .../WebGui/app/service/js/AudioFileGui.js | 14 ++----------- .../app/service/views/AudioFileGui.html | 20 +++++++++---------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/myrobotlab/audio/PlaylistPlayer.java b/src/main/java/org/myrobotlab/audio/PlaylistPlayer.java index 46396bb50b..7ff3d128f0 100644 --- a/src/main/java/org/myrobotlab/audio/PlaylistPlayer.java +++ b/src/main/java/org/myrobotlab/audio/PlaylistPlayer.java @@ -4,10 +4,14 @@ import java.util.Collections; import java.util.List; +import org.myrobotlab.logging.LoggerFactory; import org.myrobotlab.service.AudioFile; +import org.slf4j.Logger; public class PlaylistPlayer implements Runnable { + static final Logger log = LoggerFactory.getLogger(PlaylistPlayer.class); + private transient AudioFile audioFile = null; private transient Thread player; private boolean shuffle; @@ -34,6 +38,7 @@ public void run() { audioFile.play(list.get(i), true, null, track); } if (!repeat) { + log.info("finished playing playlist"); done = true; } } diff --git a/src/main/resources/resource/WebGui/app/service/js/AudioFileGui.js b/src/main/resources/resource/WebGui/app/service/js/AudioFileGui.js index 2a34217609..2510678548 100644 --- a/src/main/resources/resource/WebGui/app/service/js/AudioFileGui.js +++ b/src/main/resources/resource/WebGui/app/service/js/AudioFileGui.js @@ -8,19 +8,9 @@ angular.module('mrlapp.service.AudioFileGui', []).controller('AudioFileGuiCtrl', // playing paused stopped $scope.activity = null - // $scope.playFile = function() { - // msg.send('playFile', $scope.selectedFile) - // } - $scope.play = function() { - // if (blah){ - // $scope.selectedFile = selectedFiles[0] - // } else { - // $scope.selectedFile = selectedFiles[0] - // } let playFile = $scope.selectedFile msg.send('play', $scope.selectedFile) - } $scope.setSelectedFileFromTrack = function(selected) { @@ -29,7 +19,7 @@ angular.module('mrlapp.service.AudioFileGui', []).controller('AudioFileGuiCtrl', $scope.startPlaylist = function() { if ($scope.selectedPlaylist) { - msg.send('startPlaylist', $scope.selectedPlaylist[0]) + msg.send('startPlaylist', $scope.selectedPlaylist) } else { msg.send('startPlaylist') } @@ -37,7 +27,7 @@ angular.module('mrlapp.service.AudioFileGui', []).controller('AudioFileGuiCtrl', $scope.stopPlaylist = function() { if ($scope.selectedPlaylist) { - msg.send('stopPlaylist', $scope.selectedPlaylist[0]) + msg.send('stopPlaylist', $scope.selectedPlaylist) msg.send('stop') } else { msg.send('stopPlaylist') diff --git a/src/main/resources/resource/WebGui/app/service/views/AudioFileGui.html b/src/main/resources/resource/WebGui/app/service/views/AudioFileGui.html index ffd479fc41..77304e74f9 100644 --- a/src/main/resources/resource/WebGui/app/service/views/AudioFileGui.html +++ b/src/main/resources/resource/WebGui/app/service/views/AudioFileGui.html @@ -23,10 +23,10 @@ - - @@ -47,7 +47,7 @@ volume - {{service.volume.toFixed(2) * 100}} + {{service.config.volume.toFixed(2) * 100}} peak volume multiplier @@ -69,7 +69,7 @@
- @@ -79,10 +79,10 @@
- {{selectedPlaylist[0]}} + {{selectedPlaylist}} - +
-
+
- +
From f11717e9d7d938c24d4543c6dadc65c1174dc972 Mon Sep 17 00:00:00 2001 From: supertick Date: Fri, 26 Apr 2024 15:54:55 -0700 Subject: [PATCH 2/3] full feature jukebox --- .../org/myrobotlab/audio/PlaylistPlayer.java | 18 +++++++++++-- .../org/myrobotlab/service/AudioFile.java | 4 +++ .../service/config/AudioFileConfig.java | 10 ++++++++ .../WebGui/app/service/js/AudioFileGui.js | 22 +++++++++++----- .../app/service/views/AudioFileGui.html | 25 ++++++++++++++++--- 5 files changed, 68 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/myrobotlab/audio/PlaylistPlayer.java b/src/main/java/org/myrobotlab/audio/PlaylistPlayer.java index 7ff3d128f0..8ee40c5583 100644 --- a/src/main/java/org/myrobotlab/audio/PlaylistPlayer.java +++ b/src/main/java/org/myrobotlab/audio/PlaylistPlayer.java @@ -25,8 +25,7 @@ public PlaylistPlayer(AudioFile audioFile) { } @Override - public void run() { - + public void run() { while (!done) { List list = playlist; @@ -54,9 +53,24 @@ private List shuffle(List list) { public synchronized void stop() { done = true; + audioFile.stop(); + if (player != null) { + player.interrupt(); + } + } + + public synchronized void skip() { + if (player != null) { + audioFile.stop(); + } } + public synchronized void start(List playlist, boolean shuffle, boolean repeat, String track) { + + audioFile.getConfig().repeat = repeat; + audioFile.getConfig().shuffle = shuffle; + if (player != null) { audioFile.warn("playlist player already playing a list - stop before starting a new playlist"); return; diff --git a/src/main/java/org/myrobotlab/service/AudioFile.java b/src/main/java/org/myrobotlab/service/AudioFile.java index c383cc586c..33cf606d22 100644 --- a/src/main/java/org/myrobotlab/service/AudioFile.java +++ b/src/main/java/org/myrobotlab/service/AudioFile.java @@ -167,6 +167,7 @@ public void stopService() { p.stopPlaying(); p.interrupt(); } + playlistPlayer.stop(); } public AudioData play(String filename) { @@ -531,6 +532,9 @@ public void stopPlaylist() { playlistPlayer.stop(); } + public void skip() { + playlistPlayer.skip(); + } public double publishPeak(double peak) { log.debug("publishPeak {}", peak); diff --git a/src/main/java/org/myrobotlab/service/config/AudioFileConfig.java b/src/main/java/org/myrobotlab/service/config/AudioFileConfig.java index d0ab902aee..6901626661 100644 --- a/src/main/java/org/myrobotlab/service/config/AudioFileConfig.java +++ b/src/main/java/org/myrobotlab/service/config/AudioFileConfig.java @@ -12,6 +12,16 @@ public class AudioFileConfig extends ServiceConfig { public String currentPlaylist = "default"; + /** + * randomly shuffles a play list + */ + public boolean shuffle = false; + + /** + * repeats a playlist + */ + public boolean repeat = false; + @Deprecated /* temporal variable */ public String currentTrack = null; diff --git a/src/main/resources/resource/WebGui/app/service/js/AudioFileGui.js b/src/main/resources/resource/WebGui/app/service/js/AudioFileGui.js index 2510678548..989556d08e 100644 --- a/src/main/resources/resource/WebGui/app/service/js/AudioFileGui.js +++ b/src/main/resources/resource/WebGui/app/service/js/AudioFileGui.js @@ -4,6 +4,7 @@ angular.module('mrlapp.service.AudioFileGui', []).controller('AudioFileGuiCtrl', var msg = this.msg $scope.peak = 0 $scope.peakMax = 0 + var firstUpdate = true // playing paused stopped $scope.activity = null @@ -19,26 +20,35 @@ angular.module('mrlapp.service.AudioFileGui', []).controller('AudioFileGuiCtrl', $scope.startPlaylist = function() { if ($scope.selectedPlaylist) { - msg.send('startPlaylist', $scope.selectedPlaylist) + msg.send('startPlaylist', $scope.selectedPlaylist, $scope.service.config.shuffle, $scope.service.config.repeat) } else { msg.send('startPlaylist') } + } + $scope.skip = function() { + msg.send('skip') } $scope.stopPlaylist = function() { - if ($scope.selectedPlaylist) { - msg.send('stopPlaylist', $scope.selectedPlaylist) - msg.send('stop') - } else { msg.send('stopPlaylist') msg.send('stop') - } + } + + $scope.setPlaylist = function(name){ + console.info('setPlaylist ' + name) + msg.send('setPlaylist', name) } // GOOD TEMPLATE TO FOLLOW this.updateState = function(service) { $scope.service = service $scope.service.loudness = 20 + + if (firstUpdate){ + $scope.selectedPlaylist = $scope.service.config.currentPlaylist + firstUpdate = false + } + if (!$scope.selectedFile) { if (service.lastPlayed) { diff --git a/src/main/resources/resource/WebGui/app/service/views/AudioFileGui.html b/src/main/resources/resource/WebGui/app/service/views/AudioFileGui.html index 77304e74f9..cc488c620b 100644 --- a/src/main/resources/resource/WebGui/app/service/views/AudioFileGui.html +++ b/src/main/resources/resource/WebGui/app/service/views/AudioFileGui.html @@ -1,3 +1,10 @@ + +
@@ -81,15 +88,27 @@ {{selectedPlaylist}} - + + + +
From 1f5aa5bfa42b34c950587f6c90141c82c89bfd6a Mon Sep 17 00:00:00 2001 From: supertick Date: Fri, 26 Apr 2024 17:15:00 -0700 Subject: [PATCH 3/3] audiofile stop fix --- src/main/java/org/myrobotlab/service/AudioFile.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/myrobotlab/service/AudioFile.java b/src/main/java/org/myrobotlab/service/AudioFile.java index 33cf606d22..26abd0b9f7 100644 --- a/src/main/java/org/myrobotlab/service/AudioFile.java +++ b/src/main/java/org/myrobotlab/service/AudioFile.java @@ -356,8 +356,10 @@ public void stop() { // dump the current song // pause the next one if queued - ap.pause(false); // FIXME me shouldn't it be true ? - ap.stopPlaying(); + if (ap != null) { + ap.pause(false); // FIXME me shouldn't it be true ? + ap.stopPlaying(); + } } // FIXME - implement ???