Skip to content

Commit

Permalink
feat: "play next" command
Browse files Browse the repository at this point in the history
  • Loading branch information
phts committed Mar 28, 2023
1 parent 30610d5 commit 9120a3a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/i18n/strings_en.json
Expand Up @@ -105,6 +105,7 @@
"PASSWORD": "Password",
"PLAYER_RESTARTED": "Player successfully restarted",
"PLAYLISTS": "Playlists",
"PLAY_NEXT_ADDED": "Added to queue right after current track",
"PLAY_TEXT": "Started playback of ",
"PLAY_TITLE": "Play",
"REMOVE_FAIL": "Could not remove",
Expand Down
1 change: 1 addition & 0 deletions app/i18n/strings_ru.json
Expand Up @@ -106,6 +106,7 @@
"PLAYER_RESTARTED": "Плеер успешно перезапущен",
"PLAYLISTS": "Плейлисты",
"PLEASE_WAIT": "Пожалуйста, подождите",
"PLAY_NEXT_ADDED": "Добавлено в очередь после текущего трека",
"PLAY_TEXT": "Играет песня ",
"PLAY_TITLE": "Играет",
"REMOVE_FAIL": "Невозможно удалить",
Expand Down
5 changes: 5 additions & 0 deletions app/index.js
Expand Up @@ -435,6 +435,11 @@ class CoreCommandRouter {
}
}

async playNext(data) {
await this.stateMachine.playNext(data)
this.pushToastMessage('success', this.getI18nString('COMMON.PLAY_NEXT_ADDED'), data.title || data.uri)
}

replaceAndPlay(data) {
var self = this
var defer = libQ.defer()
Expand Down
7 changes: 7 additions & 0 deletions app/playqueue.js
Expand Up @@ -116,6 +116,13 @@ class CorePlayQueue {
return defer.promise
}

async removeItemsAfterIndex(index) {
this.commandRouter.pushConsoleMessage('CorePlayQueue::removeItemsAfterIndex ' + index)
this.arrayQueue = this.arrayQueue.slice(0, index + 1)
this.saveQueue()
await this.commandRouter.volumioPushQueue(this.arrayQueue)
}

explodeUriFromCache(service, uri) {
var self = this
var defer = libQ.defer()
Expand Down
4 changes: 4 additions & 0 deletions app/plugins/user_interface/websocket/index.js
Expand Up @@ -67,6 +67,10 @@ function InterfaceWebUI(context) {
})
})

connWebSocket.on('playNext', function (data) {
return self.commandRouter.playNext(data)
})

connWebSocket.on('replaceAndPlay', function (data) {
return self.commandRouter.replaceAndPlay(data)
})
Expand Down
8 changes: 8 additions & 0 deletions app/statemachine.js
Expand Up @@ -993,6 +993,14 @@ class CoreStateMachine {
}
}

async playNext(data) {
this.commandRouter.pushConsoleMessage('CoreStateMachine::playNext ' + JSON.stringify(data))
await this.playQueue.removeItemsAfterIndex(this.currentPosition)
await this.playQueue.addQueueItems(data)
this.setRandom(false)
this.setRepeat(false, false)
}

seek(position) {
this.commandRouter.pushConsoleMessage('CoreStateMachine::seek')

Expand Down

0 comments on commit 9120a3a

Please sign in to comment.