mirror of
https://github.com/janishutz/MusicPlayerV2.git
synced 2025-11-25 13:04:23 +00:00
lots of progress on apple music integration
This commit is contained in:
47
frontend/src/client/appleMusic/index.js
Normal file
47
frontend/src/client/appleMusic/index.js
Normal 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' );
|
||||
Reference in New Issue
Block a user