some further queue fix
This commit is contained in:
parent
c984b28ee1
commit
1ee9cba2d3
2 changed files with 139 additions and 3 deletions
|
@ -1189,7 +1189,7 @@ const app = new Vue({
|
||||||
this.getArtistFromID(id)
|
this.getArtistFromID(id)
|
||||||
//this.getTypeFromID("artist",id,isLibrary,query)
|
//this.getTypeFromID("artist",id,isLibrary,query)
|
||||||
},
|
},
|
||||||
playMediaItem(item) {
|
playMediaItem(item) {
|
||||||
let kind = (item.attributes.playParams ? (item.attributes.playParams.kind ?? (item.type ?? '')) : (item.type ?? ''));
|
let kind = (item.attributes.playParams ? (item.attributes.playParams.kind ?? (item.type ?? '')) : (item.type ?? ''));
|
||||||
let id = (item.attributes.playParams ? (item.attributes.playParams.id ?? (item.id ?? '')) : (item.id ?? ''));
|
let id = (item.attributes.playParams ? (item.attributes.playParams.id ?? (item.id ?? '')) : (item.id ?? ''));
|
||||||
;
|
;
|
||||||
|
@ -1199,7 +1199,73 @@ const app = new Vue({
|
||||||
app.mk.setStationQueue({artist: 'a-' + id}).then(() => {
|
app.mk.setStationQueue({artist: 'a-' + id}).then(() => {
|
||||||
app.mk.play()
|
app.mk.play()
|
||||||
})
|
})
|
||||||
} else {
|
} else if (kind.includes("playlist") && (id.startsWith("p.") || id.startsWith("pl.u"))){
|
||||||
|
/* Randomize array in-place using Durstenfeld shuffle algorithm */
|
||||||
|
function shuffleArray(array) {
|
||||||
|
for (var i = array.length - 1; i > 0; i--) {
|
||||||
|
var j = Math.floor(Math.random() * (i + 1));
|
||||||
|
var temp = array[i];
|
||||||
|
array[i] = array[j];
|
||||||
|
array[j] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app.mk.clearQueue().then(function () {
|
||||||
|
if ((app.showingPlaylist && app.showingPlaylist.id == id)) {
|
||||||
|
let query = app.showingPlaylist.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
|
||||||
|
if (app.mk.shuffleMode == 1){ shuffleArray(query)}
|
||||||
|
app.mk.queue.append(query)
|
||||||
|
app.mk.play()
|
||||||
|
} else {
|
||||||
|
app.mk.setQueue({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () {
|
||||||
|
app.mk.play().then(function (){
|
||||||
|
app.mk.clearQueue().then(function (){
|
||||||
|
var playlistId = id
|
||||||
|
const params = {
|
||||||
|
include: "tracks",
|
||||||
|
platform: "web",
|
||||||
|
"include[library-playlists]": "catalog,tracks",
|
||||||
|
"fields[playlists]": "curatorName,playlistType,name,artwork,url",
|
||||||
|
"include[library-songs]": "catalog,artists,albums",
|
||||||
|
"fields[catalog]": "artistUrl,albumUrl",
|
||||||
|
"fields[songs]": "artistUrl,albumUrl"
|
||||||
|
}
|
||||||
|
var playlistId = ''
|
||||||
|
|
||||||
|
try {
|
||||||
|
app.mk.api.library.playlist(id, params).then(res => {
|
||||||
|
let query = res.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
|
||||||
|
if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')}
|
||||||
|
app.mk.queue.append(query)
|
||||||
|
if (!res.relationships.tracks.next) {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
getPlaylistTracks(res.relationships.tracks.next)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPlaylistTracks(next) {
|
||||||
|
app.apiCall(app.musicBaseUrl + next, res => {
|
||||||
|
if (res.id != playlistId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let query = res.data.map(item => new MusicKit.MediaItem(item))
|
||||||
|
if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')}
|
||||||
|
app.mk.queue.append(query)
|
||||||
|
|
||||||
|
if (res.next) {
|
||||||
|
getPlaylistTracks(res.next)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
app.playMediaItemById((id), (kind), (isLibrary), item.attributes.url ?? '')
|
app.playMediaItemById((id), (kind), (isLibrary), item.attributes.url ?? '')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -395,12 +395,82 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
playTrack() {
|
playTrack() {
|
||||||
|
|
||||||
let item = this.item
|
let item = this.item
|
||||||
let parent = this.parent
|
let parent = this.parent
|
||||||
let childIndex = this.index
|
let childIndex = this.index
|
||||||
console.log(item, parent, childIndex)
|
let kind = (item.attributes.playParams ? (item.attributes.playParams.kind ?? (item.type ?? '')) : (item.type ?? ''));
|
||||||
|
let id = (item.attributes.playParams ? (item.attributes.playParams.id ?? (item.id ?? '')) : (item.id ?? ''));;
|
||||||
|
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false;
|
||||||
|
console.log(item, parent, childIndex, kind, id, isLibrary, kind == "playlists", id.startsWith("p.") || id.startsWith("pl.u"))
|
||||||
if (parent != null && childIndex != null) {
|
if (parent != null && childIndex != null) {
|
||||||
app.queueParentandplayChild(parent, childIndex, item);
|
app.queueParentandplayChild(parent, childIndex, item);
|
||||||
|
} else if (kind.includes("playlist") && (id.startsWith("p.") || id.startsWith("pl.u"))){
|
||||||
|
/* Randomize array in-place using Durstenfeld shuffle algorithm */
|
||||||
|
function shuffleArray(array) {
|
||||||
|
for (var i = array.length - 1; i > 0; i--) {
|
||||||
|
var j = Math.floor(Math.random() * (i + 1));
|
||||||
|
var temp = array[i];
|
||||||
|
array[i] = array[j];
|
||||||
|
array[j] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app.mk.clearQueue().then(function () {
|
||||||
|
if ((app.showingPlaylist && app.showingPlaylist.id == id)) {
|
||||||
|
let query = app.showingPlaylist.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
|
||||||
|
if (app.mk.shuffleMode == 1){ shuffleArray(query)}
|
||||||
|
app.mk.queue.append(query)
|
||||||
|
app.mk.play()
|
||||||
|
} else {
|
||||||
|
app.mk.setQueue({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () {
|
||||||
|
app.mk.play().then(function (){
|
||||||
|
app.mk.clearQueue().then(function (){
|
||||||
|
var playlistId = id
|
||||||
|
const params = {
|
||||||
|
include: "tracks",
|
||||||
|
platform: "web",
|
||||||
|
"include[library-playlists]": "catalog,tracks",
|
||||||
|
"fields[playlists]": "curatorName,playlistType,name,artwork,url",
|
||||||
|
"include[library-songs]": "catalog,artists,albums",
|
||||||
|
"fields[catalog]": "artistUrl,albumUrl",
|
||||||
|
"fields[songs]": "artistUrl,albumUrl"
|
||||||
|
}
|
||||||
|
var playlistId = ''
|
||||||
|
|
||||||
|
try {
|
||||||
|
app.mk.api.library.playlist(id, params).then(res => {
|
||||||
|
let query = res.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
|
||||||
|
if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')}
|
||||||
|
app.mk.queue.append(query)
|
||||||
|
if (!res.relationships.tracks.next) {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
getPlaylistTracks(res.relationships.tracks.next)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPlaylistTracks(next) {
|
||||||
|
app.apiCall(app.musicBaseUrl + next, res => {
|
||||||
|
if (res.id != playlistId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let query = res.data.map(item => new MusicKit.MediaItem(item))
|
||||||
|
if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')}
|
||||||
|
app.mk.queue.append(query)
|
||||||
|
|
||||||
|
if (res.next) {
|
||||||
|
getPlaylistTracks(res.next)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
app.playMediaItemById(item.attributes.playParams.id ?? item.id, item.attributes.playParams.kind ?? item.type, item.attributes.playParams.isLibrary ?? false, item.attributes.url)
|
app.playMediaItemById(item.attributes.playParams.id ?? item.id, item.attributes.playParams.kind ?? item.type, item.attributes.playParams.isLibrary ?? false, item.attributes.url)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue