mirror of
https://github.com/SuperBFG7/ympd
synced 2025-01-13 19:00:37 +00:00
Feat: separate update_volume notify from update_state notify
This commit is contained in:
parent
b5e2dd62c6
commit
d84cdd7d6f
@ -303,7 +303,7 @@ function appInit() {
|
||||
event.stopPropagation();
|
||||
}, false);
|
||||
domCache.volumeBar.addEventListener('change', function(event) {
|
||||
sendAPI({"cmd": "MPD_API_PLAYER_VOLUME", "data": {"volume": domCache.volumeBar.value}});
|
||||
sendAPI({"cmd": "MPD_API_PLAYER_VOLUME_SET", "data": {"volume": domCache.volumeBar.value}});
|
||||
}, false);
|
||||
|
||||
domCache.progressBar.value = 0;
|
||||
@ -766,6 +766,9 @@ function webSocketConnect() {
|
||||
case 'update_finished':
|
||||
updateDBfinished(obj.type);
|
||||
break;
|
||||
case 'update_volume':
|
||||
parseVolume(obj);
|
||||
break;
|
||||
case 'error':
|
||||
showNotification(obj.data, '', '', 'danger');
|
||||
break;
|
||||
@ -1029,20 +1032,7 @@ function parseState(obj) {
|
||||
domCache.btnsPlay[i].removeAttribute('disabled');
|
||||
|
||||
//Set volume
|
||||
if (obj.data.volume == -1) {
|
||||
domCache.volumePrct.innerText = 'Volumecontrol disabled';
|
||||
domCache.volumeControl.classList.add('hide');
|
||||
} else {
|
||||
domCache.volumeControl.classList.remove('hide');
|
||||
domCache.volumePrct.innerText = obj.data.volume + ' %';
|
||||
if (obj.data.volume == 0)
|
||||
domCache.volumeIcon.innerText = 'volume_off';
|
||||
else if (obj.data.volume < 50)
|
||||
domCache.volumeIcon.innerText = 'volume_down';
|
||||
else
|
||||
domCache.volumeIcon.innerText = 'volume_up';
|
||||
}
|
||||
domCache.volumeBar.value = obj.data.volume;
|
||||
parseVolume(obj);
|
||||
|
||||
//Set play counters
|
||||
setCounter(obj.data.currentSongId, obj.data.totalTime, obj.data.elapsedTime);
|
||||
@ -1061,6 +1051,24 @@ function parseState(obj) {
|
||||
lastState = obj;
|
||||
}
|
||||
|
||||
function parseVolume(obj) {
|
||||
if (obj.data.volume == -1) {
|
||||
domCache.volumePrct.innerText = 'Volumecontrol disabled';
|
||||
domCache.volumeControl.classList.add('hide');
|
||||
}
|
||||
else {
|
||||
domCache.volumeControl.classList.remove('hide');
|
||||
domCache.volumePrct.innerText = obj.data.volume + ' %';
|
||||
if (obj.data.volume == 0)
|
||||
domCache.volumeIcon.innerText = 'volume_off';
|
||||
else if (obj.data.volume < 50)
|
||||
domCache.volumeIcon.innerText = 'volume_down';
|
||||
else
|
||||
domCache.volumeIcon.innerText = 'volume_up';
|
||||
}
|
||||
domCache.volumeBar.value = obj.data.volume;
|
||||
}
|
||||
|
||||
function getQueue() {
|
||||
if (app.current.search.length >= 2)
|
||||
sendAPI({"cmd": "MPD_API_QUEUE_SEARCH", "data": {"filter": app.current.filter, "offset": app.current.page, "searchstr": app.current.search}}, parseQueue);
|
||||
@ -2430,7 +2438,7 @@ function chVolume(increment) {
|
||||
else if (newValue > 100)
|
||||
newValue = 100;
|
||||
domCache.volumeBar.value = newValue;
|
||||
sendAPI({"cmd": "MPD_API_PLAYER_VOLUME", "data": {"volume": newValue}});
|
||||
sendAPI({"cmd": "MPD_API_PLAYER_VOLUME_SET", "data": {"volume": newValue}});
|
||||
}
|
||||
|
||||
function beautifyDuration(x) {
|
||||
|
@ -322,13 +322,16 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||
}
|
||||
break;
|
||||
case MPD_API_PLAYER_VOLUME:
|
||||
case MPD_API_PLAYER_VOLUME_SET:
|
||||
je = json_scanf(msg.p, msg.len, "{data: {volume:%u}}", &uint_buf1);
|
||||
if (je == 1) {
|
||||
mpd_run_set_volume(mpd.conn, uint_buf1);
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||
}
|
||||
break;
|
||||
case MPD_API_PLAYER_VOLUME_GET:
|
||||
n = mympd_put_volume(mpd.buf);
|
||||
break;
|
||||
case MPD_API_PLAYER_SEEK:
|
||||
je = json_scanf(msg.p, msg.len, "{data: {songid: %u, seek: %u}}", &uint_buf1, &uint_buf2);
|
||||
if (je == 2) {
|
||||
@ -641,7 +644,7 @@ void mympd_parse_idle(struct mg_mgr *s, int idle_bitmask) {
|
||||
}
|
||||
break;
|
||||
case MPD_IDLE_MIXER:
|
||||
len = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.last_song_id, &mpd.queue_version, &mpd.queue_length);
|
||||
len = mympd_put_volume(mpd.buf);
|
||||
break;
|
||||
case MPD_IDLE_OUTPUT:
|
||||
len = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"update_outputs\"}");
|
||||
@ -1144,6 +1147,28 @@ int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, int *
|
||||
return len;
|
||||
}
|
||||
|
||||
int mympd_put_volume(char *buffer) {
|
||||
struct mpd_status *status;
|
||||
int len;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
|
||||
status = mpd_run_status(mpd.conn);
|
||||
if (!status) {
|
||||
printf("MPD mpd_run_status: %s\n", mpd_connection_get_error_message(mpd.conn));
|
||||
mpd.conn_state = MPD_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
len = json_printf(&out, "{type: update_volume, data: {"
|
||||
"volume: %d}}",
|
||||
mpd_status_get_volume(status)
|
||||
);
|
||||
mpd_status_free(status);
|
||||
|
||||
if (len > MAX_SIZE)
|
||||
printf("Buffer truncated\n");
|
||||
return len;
|
||||
}
|
||||
|
||||
int mympd_put_welcome(char *buffer) {
|
||||
int len;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
|
@ -86,7 +86,8 @@
|
||||
X(MPD_API_DATABASE_STATS) \
|
||||
X(MPD_API_DATABASE_SONGDETAILS) \
|
||||
X(MPD_API_PLAYER_PLAY_TRACK) \
|
||||
X(MPD_API_PLAYER_VOLUME) \
|
||||
X(MPD_API_PLAYER_VOLUME_SET) \
|
||||
X(MPD_API_PLAYER_VOLUME_GET) \
|
||||
X(MPD_API_PLAYER_PAUSE) \
|
||||
X(MPD_API_PLAYER_PLAY) \
|
||||
X(MPD_API_PLAYER_STOP) \
|
||||
@ -215,6 +216,7 @@ int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter
|
||||
int mympd_search(char *buffer, char *searchstr, char *filter, char *plist, unsigned int offset);
|
||||
int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
|
||||
int mympd_put_welcome(char *buffer);
|
||||
int mympd_put_volume(char *buffer);
|
||||
int mympd_put_stats(char *buffer);
|
||||
int mympd_put_settings(char *buffer);
|
||||
int mympd_put_db_tag(char *buffer, unsigned int offset, char *mpdtagtype, char *mpdsearchtagtype, char *searchstr, char *filter);
|
||||
|
Loading…
Reference in New Issue
Block a user