Add consume mode and use event to update status. (Fixes #32)

This commit is contained in:
kingosticks 2015-03-04 23:55:46 +00:00
parent aa524c8039
commit 158af8dd69
5 changed files with 36 additions and 11 deletions

View File

@ -437,12 +437,11 @@
</div>
</div>
<div data-role="footer" data-tap-toggle="false" data-position="fixed" id="nowPlayingFooter">
<!--&nbsp; <a href="#" onclick="doShuffle(); return false" title="Shuffle"><img src="images/icons/fork_21x24.png"-->
<!--id="shufflebt" alt=""/></a>-->
<p id="buttons" style="float:right; margin-top: 20px; margin-right: 5px;">
<a href="#" onclick="doRandom(); return false" title="Random"><i class="fa fa-random" id="randombt"></i></a>
&nbsp; <a href="#" onclick="doRepeat(); return false" title="Repeat"><i class="fa fa-repeat" id="repeatbt"></i></a>
&nbsp; <a href="#" onclick="doConsume(); return false" title="Consume"><i class="fa fa-cutlery" id="consumebt"></i></a>
&nbsp; <a href="#" onclick="doShuffle(); return false" title="Shuffle"><i class="fa fa-arrows-v" id="shufflebt"></i></a>
</p>

View File

@ -332,6 +332,18 @@ function setRandom(nwrandom) {
random = nwrandom;
}
function setConsume(nwconsume) {
if (consume == nwconsume) {
return
}
if (!nwconsume) {
$("#consumebt").attr('style', 'color:#2489ce');
} else {
$("#consumebt").attr('style', 'color:#66DD33');
}
consume = nwconsume;
}
function doRandom() {
if (random == false) {
//check for mopidy 0.16.x or higher
@ -370,6 +382,10 @@ function doRepeat() {
setRepeat(!repeat);
}
function doConsume() {
mopidy.tracklist.setConsume(!consume).then();
}
/*
function setRepeat(nwrepeat) {

View File

@ -16,6 +16,7 @@ var mopidy;
var play = false;
var random;
var repeat;
var consume;
var currentVolume = -1;
var muteVolume = -1;
var volumeChanging = false;

View File

@ -221,6 +221,8 @@ function initSocketevents() {
resetSong();
showOffline(true);
});
mopidy.on("event:optionsChanged", updateOptions);
mopidy.on("event:trackPlaybackStarted", function(data) {
mopidy.playback.getTimePosition().then(processCurrentposition, console.error);
@ -338,20 +340,20 @@ function updateStatusTimer() {
//TODO check offline?
}
//update tracklist options.
function updateOptions() {
mopidy.tracklist.getRepeat().then(processRepeat, console.error);
mopidy.tracklist.getRandom().then(processRandom, console.error);
mopidy.tracklist.getConsume().then(processConsume, console.error);
}
//update everything as if reloaded
function updateStatusOfAll() {
mopidy.playback.getCurrentTrack().then(processCurrenttrack, console.error);
mopidy.playback.getTimePosition().then(processCurrentposition, console.error);
mopidy.playback.getState().then(processPlaystate, console.error);
//check for mopidy 0.16 and higher
if (mopidy.tracklist.getRepeat) {
mopidy.tracklist.getRepeat().then(processRepeat, console.error);
mopidy.tracklist.getRandom().then(processRandom, console.error);
} else {
mopidy.playback.getRepeat().then(processRepeat, console.error);
mopidy.playback.getRandom().then(processRandom, console.error);
}
updateOptions()
mopidy.playback.getVolume().then(processVolume, console.error);
}
@ -608,4 +610,4 @@ function updatePlayIcons (uri) {
$(this).removeClass("currenttrack2");
}
});
}
}

View File

@ -35,6 +35,13 @@ function processRandom(data) {
setRandom(data);
}
/********************************************************
* process results of consume
*********************************************************/
function processConsume(data) {
setConsume(data);
}
/********************************************************
* process results of current position
*********************************************************/