[web-src] Make use of extended queue/item/add endpoint

Should speed up starting playback from the web ui (reduces number of web 
api requests)
This commit is contained in:
chme 2019-02-22 13:20:04 +01:00
parent d931385886
commit df455ce069
6 changed files with 55 additions and 37 deletions

View File

@ -39,23 +39,17 @@ export default {
methods: { methods: {
play: function () { play: function () {
this.$emit('close') this.$emit('close')
webapi.search({ 'type': 'tracks', 'expression': 'path starts with "' + this.directory.path + '" order by path asc' }).then(({ data }) => { webapi.player_play_expression('path starts with "' + this.directory.path + '" order by path asc', false)
webapi.player_play_uri(data.tracks.items.map(a => a.uri).join(','), false)
})
}, },
queue_add: function () { queue_add: function () {
this.$emit('close') this.$emit('close')
webapi.search({ 'type': 'tracks', 'expression': 'path starts with "' + this.directory.path + '" order by path asc' }).then(({ data }) => { webapi.queue_expression_add('path starts with "' + this.directory.path + '" order by path asc')
webapi.queue_add(data.tracks.items.map(a => a.uri).join(','))
})
}, },
queue_add_next: function () { queue_add_next: function () {
this.$emit('close') this.$emit('close')
webapi.search({ 'type': 'tracks', 'expression': 'path starts with "' + this.directory.path + '" order by path asc' }).then(({ data }) => { webapi.queue_expression_add_next('path starts with "' + this.directory.path + '" order by path asc')
webapi.queue_add_next(data.tracks.items.map(a => a.uri).join(','))
})
} }
} }
} }

View File

@ -39,23 +39,17 @@ export default {
methods: { methods: {
play: function () { play: function () {
this.$emit('close') this.$emit('close')
webapi.library_genre_tracks(this.genre.name).then(({ data }) => webapi.player_play_expression('genre is "' + this.genre.name + '" and media_kind is music', false)
webapi.player_play_uri(data.tracks.items.map(a => a.uri).join(','), false)
)
}, },
queue_add: function () { queue_add: function () {
this.$emit('close') this.$emit('close')
webapi.library_genre_tracks(this.genre.name).then(({ data }) => webapi.queue_expression_add('genre is "' + this.genre.name + '" and media_kind is music')
webapi.queue_add(data.tracks.items.map(a => a.uri).join(','))
)
}, },
queue_add_next: function () { queue_add_next: function () {
this.$emit('close') this.$emit('close')
webapi.library_genre_tracks(this.genre.name).then(({ data }) => webapi.queue_expression_add_next('genre is "' + this.genre.name + '" and media_kind is music')
webapi.queue_add_next(data.tracks.items.map(a => a.uri).join(','))
)
}, },
open_genre: function () { open_genre: function () {

View File

@ -153,9 +153,7 @@ export default {
}, },
play: function () { play: function () {
webapi.search({ 'type': 'tracks', 'expression': 'path starts with "' + this.current_directory + '" order by path asc' }).then(({ data }) => { webapi.player_play_expression('path starts with "' + this.current_directory + '" order by path asc', false)
webapi.player_play_uri(data.tracks.items.map(a => a.uri).join(','), false)
})
}, },
play_track: function (position) { play_track: function (position) {

View File

@ -85,9 +85,7 @@ export default {
}, },
play: function () { play: function () {
webapi.library_genre_tracks(this.name).then(({ data }) => webapi.player_play_expression('genre is "' + this.name + '" and media_kind is music', true)
webapi.player_play_uri(data.tracks.items.map(a => a.uri).join(','), true)
)
}, },
open_album: function (album) { open_album: function (album) {

View File

@ -84,11 +84,11 @@ export default {
}, },
play: function () { play: function () {
webapi.player_play_uri(this.tracks.items.map(a => a.uri).join(','), true) webapi.player_play_expression('genre is "' + this.genre + '" and media_kind is music', true)
}, },
play_track: function (position) { play_track: function (position) {
webapi.player_play_uri(this.tracks.items.map(a => a.uri).join(','), false, position) webapi.player_play_expression('genre is "' + this.genre + '" and media_kind is music', false, position)
}, },
open_dialog: function (track) { open_dialog: function (track) {

View File

@ -41,11 +41,9 @@ export default {
return axios.put('/api/queue/items/' + itemId + '?new_position=' + newPosition) return axios.put('/api/queue/items/' + itemId + '?new_position=' + newPosition)
}, },
queue_add (uri, showNotification = true) { queue_add (uri) {
return axios.post('/api/queue/items/add?uris=' + uri).then((response) => { return axios.post('/api/queue/items/add?uris=' + uri).then((response) => {
if (showNotification) {
store.dispatch('add_notification', { text: response.data.count + ' tracks appended to queue', type: 'info', timeout: 2000 }) store.dispatch('add_notification', { text: response.data.count + ' tracks appended to queue', type: 'info', timeout: 2000 })
}
return Promise.resolve(response) return Promise.resolve(response)
}) })
}, },
@ -61,18 +59,54 @@ export default {
}) })
}, },
queue_expression_add (expression) {
var options = {}
options.expression = expression
return axios.post('/api/queue/items/add', undefined, { params: options }).then((response) => {
store.dispatch('add_notification', { text: response.data.count + ' tracks appended to queue', type: 'info', timeout: 2000 })
return Promise.resolve(response)
})
},
queue_expression_add_next (expression) {
var options = {}
options.expression = expression
options.position = 0
if (store.getters.now_playing && store.getters.now_playing.id) {
options.position = store.getters.now_playing.position + 1
}
return axios.post('/api/queue/items/add', undefined, { params: options }).then((response) => {
store.dispatch('add_notification', { text: response.data.count + ' tracks appended to queue', type: 'info', timeout: 2000 })
return Promise.resolve(response)
})
},
player_status () { player_status () {
return axios.get('/api/player') return axios.get('/api/player')
}, },
player_play_uri (uris, shuffle, position = undefined) { player_play_uri (uris, shuffle, position = undefined) {
return this.queue_clear().then(() => var options = {}
this.player_shuffle(shuffle).then(() => options.uris = uris
this.queue_add(uris, false).then(() => options.shuffle = shuffle ? 'true' : 'false'
this.player_play({ 'position': position }) options.clear = 'true'
) options.playback = 'start'
) options.playback_from_position = position
)
return axios.post('/api/queue/items/add', undefined, { params: options })
},
player_play_expression (expression, shuffle, position = undefined) {
var options = {}
options.expression = expression
options.shuffle = shuffle ? 'true' : 'false'
options.clear = 'true'
options.playback = 'start'
options.playback_from_position = position
return axios.post('/api/queue/items/add', undefined, { params: options })
}, },
player_play (options = {}) { player_play (options = {}) {