From f11717e9d7d938c24d4543c6dadc65c1174dc972 Mon Sep 17 00:00:00 2001 From: supertick Date: Fri, 26 Apr 2024 15:54:55 -0700 Subject: [PATCH] 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}} - + + + +