🐛 (spotify)
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
content="width=device-width,initial-scale=1.0,user-scalable=no"
|
content="width=device-width,initial-scale=1.0,user-scalable=no"
|
||||||
/>
|
/>
|
||||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
|
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
|
||||||
<script src="https://sdk.scdn.co/spotify-player.js"></script>
|
|
||||||
<title>Binôme</title>
|
<title>Binôme</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ import {
|
|||||||
playOnSpotify,
|
playOnSpotify,
|
||||||
pauseOnSpotify
|
pauseOnSpotify
|
||||||
} from '@/utils/spotify'
|
} from '@/utils/spotify'
|
||||||
import { ref, reactive } from '@vue/composition-api'
|
import { ref, reactive, onMounted } from '@vue/composition-api'
|
||||||
|
|
||||||
window.onSpotifyWebPlaybackSDKReady = () => {}
|
|
||||||
|
|
||||||
export const useSpotify = (onPlay: () => void, onPause: () => void) => {
|
export const useSpotify = (onPlay: () => void, onPause: () => void) => {
|
||||||
const ready = ref(false)
|
const ready = ref(false)
|
||||||
@@ -26,43 +24,46 @@ export const useSpotify = (onPlay: () => void, onPause: () => void) => {
|
|||||||
RootActions
|
RootActions
|
||||||
>(['setAccessToken', 'setTokenExpire', 'setHasSpotify'])
|
>(['setAccessToken', 'setTokenExpire', 'setHasSpotify'])
|
||||||
|
|
||||||
window.onSpotifyWebPlaybackSDKReady = async () => {
|
onMounted(() => {
|
||||||
if (!hasValidAccessToken.value) {
|
window.onSpotifyWebPlaybackSDKReady = async () => {
|
||||||
redirectToSpotifyConnect()
|
if (!hasValidAccessToken.value) {
|
||||||
return
|
redirectToSpotifyConnect()
|
||||||
}
|
|
||||||
|
|
||||||
spotify.player = new Spotify.Player({
|
|
||||||
name: 'binome',
|
|
||||||
getOAuthToken: (callback) => callback(accessToken.value)
|
|
||||||
})
|
|
||||||
spotify.player.addListener('ready', ({ device_id }) => {
|
|
||||||
deviceId.value = device_id
|
|
||||||
ready.value = true
|
|
||||||
})
|
|
||||||
spotify.player.addListener('player_state_changed', (state) => {
|
|
||||||
console.log('player state changed', state)
|
|
||||||
if (!state) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
!state.paused ? onPlay() : onPause()
|
|
||||||
})
|
spotify.player = new Spotify.Player({
|
||||||
spotify.player.addListener('not_ready', () => {
|
name: 'binome',
|
||||||
setAccessToken(null)
|
getOAuthToken: (callback) => callback(accessToken.value)
|
||||||
setTokenExpire(null)
|
})
|
||||||
setHasSpotify(false)
|
spotify.player.addListener('ready', ({ device_id }) => {
|
||||||
})
|
deviceId.value = device_id
|
||||||
spotify.player.on('playback_error', (error) => {
|
ready.value = true
|
||||||
console.error('Failed to perform playback', error)
|
})
|
||||||
})
|
spotify.player.addListener('player_state_changed', (state) => {
|
||||||
spotify.player.on('account_error', (error) => {
|
console.log('player state changed', state)
|
||||||
console.error('account_error', error)
|
if (!state) {
|
||||||
})
|
return
|
||||||
spotify.player.on('initialization_error', (error) => {
|
}
|
||||||
console.error('initialization_error', error)
|
!state.paused ? onPlay() : onPause()
|
||||||
})
|
})
|
||||||
await spotify.player.connect()
|
spotify.player.addListener('not_ready', () => {
|
||||||
}
|
setAccessToken(null)
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
import('@/lib/spotify-player')
|
||||||
|
})
|
||||||
|
|
||||||
const play = async () => {
|
const play = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ export const redirectToSpotifyConnect = () => {
|
|||||||
)
|
)
|
||||||
authorizeURL.searchParams.append('response_type', 'token')
|
authorizeURL.searchParams.append('response_type', 'token')
|
||||||
authorizeURL.searchParams.append('show_dialog', 'false')
|
authorizeURL.searchParams.append('show_dialog', 'false')
|
||||||
authorizeURL.searchParams.append('scope', 'user-modify-playback-state')
|
authorizeURL.searchParams.append(
|
||||||
|
'scope',
|
||||||
|
'streaming,user-modify-playback-state'
|
||||||
|
)
|
||||||
authorizeURL.searchParams.append('redirect_uri', `${location.origin}/spotify`)
|
authorizeURL.searchParams.append('redirect_uri', `${location.origin}/spotify`)
|
||||||
|
|
||||||
location.href = authorizeURL.toString()
|
location.href = authorizeURL.toString()
|
||||||
|
|||||||
Reference in New Issue
Block a user