🐛 (spotify)

This commit is contained in:
2020-07-22 23:27:28 +02:00
parent 857d9083ca
commit 697c9df7fd
2 changed files with 15 additions and 1 deletions

View File

@@ -1,7 +1,6 @@
/* eslint-disable */
// @ts-ignore
// @ts-nocheck
import '@/lib/spotify-player'
import { useGetters, useActions } from 'vuex-composition-helpers'
import { GetterTree } from 'vuex'
import { State, RootActions } from '@/store'
@@ -12,6 +11,8 @@ import {
} from '@/utils/spotify'
import { ref, reactive } from '@vue/composition-api'
window.onSpotifyWebPlaybackSDKReady = () => {}
export const useSpotify = (onPlay: () => void, onPause: () => void) => {
const ready = ref(false)
const deviceId = ref<string | null>(null)
@@ -41,6 +42,9 @@ export const useSpotify = (onPlay: () => void, onPause: () => void) => {
})
spotify.player.addListener('player_state_changed', (state) => {
console.log('player state changed', state)
if (!state) {
return
}
!state.paused ? onPlay() : onPause()
})
spotify.player.addListener('not_ready', () => {
@@ -48,6 +52,15 @@ export const useSpotify = (onPlay: () => void, onPause: () => void) => {
setTokenExpire(null)
setHasSpotify(false)
})
spotify.player.on('playback_error', (error) => {
console.error('Failed to perform playback', error)
})
spotify.player.on('account_error', (error) => {
console.error('account_error', error)
})
spotify.player.on('initialization_error', (error) => {
console.error('initialization_error', error)
})
await spotify.player.connect()
}