Skip to content

Commit

Permalink
Add pause functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ara-vardanyan authored and lukeocodes committed May 5, 2024
1 parent 688278c commit 5800966
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ interface NowPlayingContext extends Partial<Omit<HTMLAudioElement, "play">> {
*/
play: (audio: MediaSource | Blob | string, type?: string, uid?: string) => Promise<void>;

/**
* Pauses audio playback at the current position.
*/
pause: () => void;

/**
* Resumes audio playback from the current position.
*/
Expand Down Expand Up @@ -105,6 +110,12 @@ const NowPlayingContextProvider = ({ children }: NowPlayingContextInterface) =>
return player.play();
};

const pause = () => {
if (!player) return;

player.pause();
};

const stop = () => {
if (!player) return;

Expand All @@ -124,6 +135,7 @@ const NowPlayingContextProvider = ({ children }: NowPlayingContextInterface) =>
value={{
player,
play,
pause,
resume,
stop,
uid,
Expand Down

1 comment on commit 5800966

@vercel
Copy link

@vercel vercel bot commented on 5800966 May 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.