lots of progress on apple music integration

This commit is contained in:
2023-11-14 20:19:36 +01:00
parent 83303be8e9
commit 2b3af0de24
10 changed files with 119 additions and 54 deletions

View File

@@ -0,0 +1,47 @@
const app = Vue.createApp( {
data() {
return {
musicKit: null,
isLoggedIn: false,
}
},
methods: {
logInto() {
if ( !this.musicKit.isAuthorized ) {
this.musicKit.authorize().then( () => {
this.musicKit.play();
this.isLoggedIn();
} );
}
},
initMusicKit () {
fetch( '/getAppleMusicDevToken' ).then( res => {
if ( res.status === 200 ) {
res.text().then( token => {
// MusicKit global is now defined
MusicKit.configure( {
developerToken: token,
app: {
name: 'MusicPlayer',
build: '2'
}
} );
this.musicKit = MusicKit.getInstance();
if ( this.musicKit.isAuthorized ) {
this.isLoggedIn = true;
}
} );
}
} );
}
},
created() {
if ( !window.MusicKit ) {
document.addEventListener( 'musickitloaded', () => {
self.initMusicKit();
} );
} else {
this.initMusicKit();
}
},
} ).mount( '#app' );