Skip to content

Commit

Permalink
full feature jukebox
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Apr 26, 2024
1 parent 63da898 commit f11717e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 11 deletions.
18 changes: 16 additions & 2 deletions src/main/java/org/myrobotlab/audio/PlaylistPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public PlaylistPlayer(AudioFile audioFile) {
}

@Override
public void run() {

public void run() {
while (!done) {

List<String> list = playlist;
Expand Down Expand Up @@ -54,9 +53,24 @@ private List<String> shuffle(List<String> 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<String> 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;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/myrobotlab/service/AudioFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public void stopService() {
p.stopPlaying();
p.interrupt();
}
playlistPlayer.stop();
}

public AudioData play(String filename) {
Expand Down Expand Up @@ -531,6 +532,9 @@ public void stopPlaylist() {
playlistPlayer.stop();
}

public void skip() {
playlistPlayer.skip();
}

public double publishPeak(double peak) {
log.debug("publishPeak {}", peak);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/myrobotlab/service/config/AudioFileConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
22 changes: 16 additions & 6 deletions src/main/resources/resource/WebGui/app/service/js/AudioFileGui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<style>
.active-toggle {
background-color: #286090; /* Blue color for active state */
color: white;
}
</style>

<div class="col-md-6">
<table border="1" class="table table-hover table-condensed table-striped table-bordered">
<tr>
Expand Down Expand Up @@ -81,15 +88,27 @@
<label>select playlist:</label>
{{selectedPlaylist}}

<select size="8" class="form-control vertical-menu" ng-change="msg.send('setPlaylist', name)" ng-model="selectedPlaylist" id="service.config.playlists" title="select your playlist">
<select size="8" class="form-control vertical-menu" ng-change="setPlaylist(selectedPlaylist)" ng-model="selectedPlaylist" id="service.config.playlists" title="select your playlist">
<option ng-repeat="(name, fileset) in service.config.playlists" ng-value="{{name}}">{{name}}</option>
</select>
</div>
<button class="btn btn-default" ng-click="startPlaylist()">
<span class="glyphicon glyphicon-play" title="play list"/>
<span class="glyphicon glyphicon-play" title="Start Play List"/>
</button>
<button class="btn btn-default" ng-click="stopPlaylist()">
<span class="glyphicon glyphicon-stop" title="stop play list"/>
<span class="glyphicon glyphicon-stop" title="Stop Play List"/>
</button>

<button class="btn btn-default" title="Skip" ng-click="skip()">
<span class="glyphicon glyphicon-forward"></span>
</button>
<button class="btn btn-default" ng-click="service.config.shuffle = !service.config.shuffle"
ng-class="{'active-toggle': service.config.shuffle}">
<span class="glyphicon glyphicon-random" title="Shuffle Playlist"></span>
</button>
<button class="btn btn-default" ng-click="service.config.repeat = !service.config.repeat"
ng-class="{'active-toggle': service.config.repeat}">
<span class="glyphicon glyphicon-refresh" title="Repeat Playlist"></span>
</button>
<div ng-show="service.config.playlists" class="form-group">
<label>select file:</label>
Expand Down

0 comments on commit f11717e

Please sign in to comment.