mirror of
https://github.com/R0m1k3/podcastic.git
synced 2026-10-24 15:38:03 +02:00
feat: implement global audio player with playback controls, progress tracking, and persistent settings
This commit is contained in:
1 parent
c9127c70c1
commit
17f2496dda
9 files changed
+274
-109
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import React, { createContext, useContext, useState, ReactNode } from 'react';
|
||||
import { Episode } from '../services/episodeService';
|
||||
|
||||
interface AudioContextType {
|
||||
currentEpisode: Episode | null;
|
||||
isPlaying: boolean;
|
||||
playEpisode: (episode: Episode) => void;
|
||||
togglePlay: () => void;
|
||||
closePlayer: () => void;
|
||||
setIsPlaying: (isPlaying: boolean) => void;
|
||||
}
|
||||
|
||||
const AudioContext = createContext<AudioContextType | undefined>(undefined);
|
||||
|
||||
export function AudioProvider({ children }: { children: ReactNode }) {
|
||||
const [currentEpisode, setCurrentEpisode] = useState<Episode | null>(null);
|
||||
const [isPlaying, setIsPlaying] = useState(false);
|
||||
|
||||
const playEpisode = (episode: Episode) => {
|
||||
setCurrentEpisode(episode);
|
||||
setIsPlaying(true);
|
||||
};
|
||||
|
||||
const togglePlay = () => {
|
||||
setIsPlaying(prev => !prev);
|
||||
};
|
||||
|
||||
const closePlayer = () => {
|
||||
setCurrentEpisode(null);
|
||||
setIsPlaying(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<AudioContext.Provider value={{
|
||||
currentEpisode,
|
||||
isPlaying,
|
||||
playEpisode,
|
||||
togglePlay,
|
||||
closePlayer,
|
||||
setIsPlaying
|
||||
}}>
|
||||
{children}
|
||||
</AudioContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useAudio() {
|
||||
const context = useContext(AudioContext);
|
||||
if (context === undefined) {
|
||||
throw new Error('useAudio must be used within an AudioProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
Reference in new issue
Block a user