play walkout songs
This commit is contained in:
@@ -165,16 +165,16 @@ export const SpotifyProvider: React.FC<PropsWithChildren> = ({ children }) => {
|
||||
|
||||
const play = useCallback(async (deviceId?: string) => {
|
||||
if (!authState.isAuthenticated) return;
|
||||
|
||||
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
|
||||
try {
|
||||
await makeSpotifyRequest('playback', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ action: 'play', deviceId }),
|
||||
});
|
||||
|
||||
|
||||
setTimeout(refreshPlaybackState, 500);
|
||||
} catch (error) {
|
||||
if (error instanceof Error && !error.message.includes('JSON')) {
|
||||
@@ -186,6 +186,29 @@ export const SpotifyProvider: React.FC<PropsWithChildren> = ({ children }) => {
|
||||
}
|
||||
}, [authState.isAuthenticated]);
|
||||
|
||||
const playTrack = useCallback(async (trackId: string, deviceId?: string, positionMs?: number) => {
|
||||
if (!authState.isAuthenticated) return;
|
||||
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
await makeSpotifyRequest('playback', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ action: 'playTrack', trackId, deviceId, positionMs }),
|
||||
});
|
||||
|
||||
setTimeout(refreshPlaybackState, 500);
|
||||
} catch (error) {
|
||||
if (error instanceof Error && !error.message.includes('JSON')) {
|
||||
setError(error.message);
|
||||
}
|
||||
console.warn('Track playback action completed with warning:', error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [authState.isAuthenticated]);
|
||||
|
||||
const pause = useCallback(async () => {
|
||||
if (!authState.isAuthenticated) return;
|
||||
|
||||
@@ -422,6 +445,7 @@ export const SpotifyProvider: React.FC<PropsWithChildren> = ({ children }) => {
|
||||
login,
|
||||
logout,
|
||||
play,
|
||||
playTrack,
|
||||
pause,
|
||||
skipNext,
|
||||
skipPrevious,
|
||||
|
||||
Reference in New Issue
Block a user