🐛 (spotify)
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
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>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import '@/lib/spotify-player'
|
|
||||||
import { useGetters, useActions } from 'vuex-composition-helpers'
|
import { useGetters, useActions } from 'vuex-composition-helpers'
|
||||||
import { GetterTree } from 'vuex'
|
import { GetterTree } from 'vuex'
|
||||||
import { State, RootActions } from '@/store'
|
import { State, RootActions } from '@/store'
|
||||||
@@ -12,6 +11,8 @@ import {
|
|||||||
} from '@/utils/spotify'
|
} from '@/utils/spotify'
|
||||||
import { ref, reactive } from '@vue/composition-api'
|
import { ref, reactive } 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)
|
||||||
const deviceId = ref<string | null>(null)
|
const deviceId = ref<string | null>(null)
|
||||||
@@ -41,6 +42,9 @@ export const useSpotify = (onPlay: () => void, onPause: () => void) => {
|
|||||||
})
|
})
|
||||||
spotify.player.addListener('player_state_changed', (state) => {
|
spotify.player.addListener('player_state_changed', (state) => {
|
||||||
console.log('player state changed', state)
|
console.log('player state changed', state)
|
||||||
|
if (!state) {
|
||||||
|
return
|
||||||
|
}
|
||||||
!state.paused ? onPlay() : onPause()
|
!state.paused ? onPlay() : onPause()
|
||||||
})
|
})
|
||||||
spotify.player.addListener('not_ready', () => {
|
spotify.player.addListener('not_ready', () => {
|
||||||
@@ -48,6 +52,15 @@ export const useSpotify = (onPlay: () => void, onPause: () => void) => {
|
|||||||
setTokenExpire(null)
|
setTokenExpire(null)
|
||||||
setHasSpotify(false)
|
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()
|
await spotify.player.connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,20 +20,6 @@ export const redirectToSpotifyConnect = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const playOnSpotify = async (token: string, deviceId: string) => {
|
export const playOnSpotify = async (token: string, deviceId: string) => {
|
||||||
// const response = await fetch(
|
|
||||||
// `https://api.spotify.com/v1/me/player/shuffle?device_id=${deviceId}&state=true`,
|
|
||||||
// {
|
|
||||||
// method: 'PUT',
|
|
||||||
// headers: {
|
|
||||||
// accept: 'application/json',
|
|
||||||
// 'content-type': 'application/json',
|
|
||||||
// authorization: `Bearer ${token}`
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
|
|
||||||
// console.log(await response.json())
|
|
||||||
|
|
||||||
await fetch(
|
await fetch(
|
||||||
`https://api.spotify.com/v1/me/player/play?device_id=${deviceId}`,
|
`https://api.spotify.com/v1/me/player/play?device_id=${deviceId}`,
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user