some queue fix
This commit is contained in:
parent
0aa402b6aa
commit
b638a2c877
3 changed files with 103 additions and 24 deletions
|
@ -1194,7 +1194,7 @@ const app = new Vue({
|
||||||
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 ?? ''));
|
||||||
;
|
;
|
||||||
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false;
|
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false;
|
||||||
|
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
|
||||||
console.log(kind, id, isLibrary)
|
console.log(kind, id, isLibrary)
|
||||||
app.mk.stop().then(() => {
|
app.mk.stop().then(() => {
|
||||||
if (kind.includes("artist")) {
|
if (kind.includes("artist")) {
|
||||||
|
@ -1212,7 +1212,7 @@ const app = new Vue({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.mk.clearQueue().then(function () { {
|
app.mk.clearQueue().then(function () { {
|
||||||
app.mk.setQueue({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () {
|
app.mk.setQueue({[truekind]: [item.attributes.playParams.id ?? item.id]}).then(function () {
|
||||||
app.mk.play().then(function (){
|
app.mk.play().then(function (){
|
||||||
app.mk.clearQueue().then(function (){
|
app.mk.clearQueue().then(function (){
|
||||||
var playlistId = id
|
var playlistId = id
|
||||||
|
|
|
@ -410,12 +410,12 @@
|
||||||
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 ?? ''));;
|
||||||
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false;
|
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false;
|
||||||
|
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
|
||||||
console.log(item, parent, childIndex, kind, id, isLibrary, kind == "playlists", id.startsWith("p.") || id.startsWith("pl.u"))
|
console.log(item, parent, childIndex, kind, id, isLibrary, kind == "playlists", id.startsWith("p.") || id.startsWith("pl.u"))
|
||||||
app.mk.stop().then(() => {
|
app.mk.stop().then(() => {
|
||||||
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."))){
|
} else if (kind.includes("playlist") && (id.startsWith("p.") || id.startsWith("pl."))){
|
||||||
/* Randomize array in-place using Durstenfeld shuffle algorithm */
|
|
||||||
function shuffleArray(array) {
|
function shuffleArray(array) {
|
||||||
for (var i = array.length - 1; i > 0; i--) {
|
for (var i = array.length - 1; i > 0; i--) {
|
||||||
var j = Math.floor(Math.random() * (i + 1));
|
var j = Math.floor(Math.random() * (i + 1));
|
||||||
|
@ -425,20 +425,20 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.mk.clearQueue().then(function () {
|
app.mk.clearQueue().then(function () {
|
||||||
app.mk.setQueue({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () {
|
app.mk.setQueue({[truekind]: [item.attributes.playParams.id ?? item.id]}).then(function () {
|
||||||
app.mk.play().then(function (){
|
app.mk.play().then(function (){
|
||||||
app.mk.clearQueue().then(function (){
|
app.mk.clearQueue().then(function (){
|
||||||
var playlistId = id
|
var playlistId = id
|
||||||
const params = {
|
const params = {
|
||||||
include: "tracks",
|
// include: "tracks",
|
||||||
platform: "web",
|
// platform: "web",
|
||||||
"include[library-playlists]": "catalog,tracks",
|
// "include[library-playlists]": "catalog,tracks",
|
||||||
"fields[playlists]": "curatorName,playlistType,name,artwork,url",
|
// "fields[playlists]": "curatorName,playlistType,name,artwork,url",
|
||||||
"include[library-songs]": "catalog,artists,albums",
|
// "include[library-songs]": "catalog,artists,albums",
|
||||||
"fields[catalog]": "artistUrl,albumUrl",
|
// "fields[catalog]": "artistUrl,albumUrl",
|
||||||
"fields[songs]": "artistUrl,albumUrl"
|
// "fields[songs]": "artistUrl,albumUrl, playParams"
|
||||||
}
|
}
|
||||||
var playlistId = ''
|
// var playlistId = ''
|
||||||
function getPlaylist(id, params, isLibrary){
|
function getPlaylist(id, params, isLibrary){
|
||||||
if (isLibrary){
|
if (isLibrary){
|
||||||
return app.mk.api.library.playlist(id, params)
|
return app.mk.api.library.playlist(id, params)
|
||||||
|
@ -448,7 +448,8 @@
|
||||||
|
|
||||||
getPlaylist(id, params, isLibrary).then(res => {
|
getPlaylist(id, params, isLibrary).then(res => {
|
||||||
let query = res.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
|
let query = res.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
|
||||||
if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')}
|
if (app.mk.shuffleMode == 1){shuffleArray(query); }
|
||||||
|
console.log(query)
|
||||||
app.mk.queue.append(query)
|
app.mk.queue.append(query)
|
||||||
if (!res.relationships.tracks.next) {
|
if (!res.relationships.tracks.next) {
|
||||||
return
|
return
|
||||||
|
@ -458,9 +459,10 @@
|
||||||
|
|
||||||
function getPlaylistTracks(next) {
|
function getPlaylistTracks(next) {
|
||||||
app.apiCall(app.musicBaseUrl + next, res => {
|
app.apiCall(app.musicBaseUrl + next, res => {
|
||||||
if (res.id != playlistId) {
|
// if (res.id != playlistId || next.includes(playlistId)) {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
console.log('nextres', res)
|
||||||
let query = res.data.map(item => new MusicKit.MediaItem(item))
|
let query = res.data.map(item => new MusicKit.MediaItem(item))
|
||||||
if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')}
|
if (app.mk.shuffleMode == 1){shuffleArray(query); console.log('shf')}
|
||||||
app.mk.queue.append(query)
|
app.mk.queue.append(query)
|
||||||
|
|
|
@ -59,11 +59,11 @@
|
||||||
</template>
|
</template>
|
||||||
<div class="playlist-controls">
|
<div class="playlist-controls">
|
||||||
<button class="wr-btn" style="min-width: 120px;"
|
<button class="wr-btn" style="min-width: 120px;"
|
||||||
@click="app.mk.shuffleMode = 0;app.playMediaItemById(data.attributes.playParams.id ?? data.id, data.attributes.playParams.kind ?? data.type, data.attributes.playParams.isLibrary ?? false, data.attributes.url)">
|
@click="app.mk.shuffleMode = 0; app.mk.stop().then(function() {app.playMediaItemById(data.attributes.playParams.id ?? data.id, data.attributes.playParams.kind ?? data.type, data.attributes.playParams.isLibrary ?? false, data.attributes.url)})">
|
||||||
Play
|
Play
|
||||||
</button>
|
</button>
|
||||||
<button class="wr-btn" style="min-width: 120px;"
|
<button class="wr-btn" style="min-width: 120px;"
|
||||||
@click="app.mk.shuffleMode = 1;app.playMediaItemById(data.attributes.playParams.id ?? data.id, data.attributes.playParams.kind ?? data.type, data.attributes.playParams.isLibrary ?? false, data.attributes.url)">
|
@click="shufflePlay()">
|
||||||
Shuffle
|
Shuffle
|
||||||
</button>
|
</button>
|
||||||
<button class="wr-btn" style="min-width: 120px;" v-if="inLibrary!=null"
|
<button class="wr-btn" style="min-width: 120px;" v-if="inLibrary!=null"
|
||||||
|
@ -312,7 +312,84 @@
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
shufflePlay() {
|
||||||
|
app.mk.shuffleMode = 1;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var id = this.data.attributes.playParams.id ?? this.data.id
|
||||||
|
let kind = this.data.attributes.playParams.kind ?? this.data.type ?? '';
|
||||||
|
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
|
||||||
|
let isLibrary = this.data.attributes.playParams ? (this.data.attributes.playParams.isLibrary ?? false) : false;
|
||||||
|
app.mk.stop().then(function() {
|
||||||
|
app.mk.clearQueue().then(function () {
|
||||||
|
app.mk.setQueue({ [truekind] : [id] }).then(function () {
|
||||||
|
app.mk.play().then(function () {
|
||||||
|
app.mk.clearQueue().then(function () {
|
||||||
|
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, playParams"
|
||||||
|
}
|
||||||
|
function getList(kind, id, params, isLibrary) {
|
||||||
|
if (kind.includes("album")){
|
||||||
|
if (isLibrary) {
|
||||||
|
return app.mk.api.library.album(id, params)
|
||||||
|
} else { return app.mk.api.album(id, params) }
|
||||||
|
} else {
|
||||||
|
if (isLibrary) {
|
||||||
|
return app.mk.api.library.playlist(id, params)
|
||||||
|
} else { return app.mk.api.playlist(id, params) }}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
|
||||||
|
getPlaylist(kind, id, params, isLibrary).then(res => {
|
||||||
|
console.log(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) {console.log(e) }
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
})}
|
||||||
|
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue