1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-12-23 01:20:27 +00:00

Added option for automatic playback of mpd stream.

When activated in settings, ympd will atempt to play the mpd stream
(ogg/mp3) locally in the browser whenever mpd is playing.

This allows to run a headless instance on a PC with sound and start/stop
playback also from other instances or mpd clients.
e.g. run ympd with autoplay on your private PC with decent loudspeakers,
    but control it with another instance on your office laptop without
    the need to switch PCs.
This commit is contained in:
SuperBFG7 2021-03-23 19:25:39 +01:00
parent 5e6d090bd8
commit d1416d8f34
2 changed files with 22 additions and 7 deletions

View File

@ -281,14 +281,14 @@
<input type="text" class="form-control" id="mpdstream" /> <input type="text" class="form-control" id="mpdstream" />
</div> </div>
</div> </div>
</form>
<div class="row"> <div class="row">
<div class="form-group col-md-12"> <div class="form-group col-md-12" data-toggle="buttons">
<button type="button" class="btn btn-default" onclick="updateDB();"> <button type="button" class="btn btn-default btn-block" id="btnautoplay">
<span class="glyphicon glyphicon-refresh"></span> Update DB <span class="glyphicon glyphicon-play"></span> Autoplay stream in this browser when mpd is playing
</button> </button>
</div> </div>
</div> </div>
</form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>

View File

@ -199,6 +199,9 @@ $(document).ready(function(){
if ($.cookie("notification") === "true") if ($.cookie("notification") === "true")
$('#btnnotify').addClass("active") $('#btnnotify').addClass("active")
if ($.cookie("autoplay") === "true")
$('#btnautoplay').addClass("active")
document.getElementById('player').addEventListener('stalled', function() { document.getElementById('player').addEventListener('stalled', function() {
if ( !document.getElementById('player').paused ) { if ( !document.getElementById('player').paused ) {
this.pause(); this.pause();
@ -765,6 +768,9 @@ var updatePlayIcon = function(state)
} else if(state == 2) { // play } else if(state == 2) { // play
$("#play-icon").addClass("glyphicon-pause"); $("#play-icon").addClass("glyphicon-pause");
$('#track-icon').addClass("glyphicon-play"); $('#track-icon').addClass("glyphicon-play");
if ( ($.cookie("autoplay") === "true") && (player.paused) ) {
clickLocalPlay();
}
} else { // pause } else { // pause
$("#play-icon").addClass("glyphicon-play"); $("#play-icon").addClass("glyphicon-play");
$('#track-icon').addClass("glyphicon-pause"); $('#track-icon').addClass("glyphicon-pause");
@ -925,6 +931,15 @@ $('#btnnotify').on('click', function (e) {
} }
}); });
$('#btnautoplay').on('click', function (e) {
if($.cookie("autoplay") === "true") {
$.cookie("autoplay", false);
} else {
$.cookie("autoplay", true, { expires: 424242 });
$('#btnautoplay').addClass("active");
}
});
function getHost() { function getHost() {
socket.send('MPD_API_GET_MPDHOST'); socket.send('MPD_API_GET_MPDHOST');