Skip to main content

pause

The Pause function pause an audio file.

Example

Pause sound with onClick Event

If you run the play function and then run the pause function, the audio will pause.
When you run the play function again, it will pick up where it left off.

When you pause, isPlaying becomes false and isPause becomes true.
If you play again, isPlaying becomes true and isPause becomes false.

import { useAudio } from "react-use-audio";

// You need to add sound-related files
import testSound from "./sounds/test.mp3";

function App() {
const {
data: { isPlaying, isPause },
play,
pause,
} = useAudio(testSound);

return (
<>
<p>isPlaying: {isPlaying ? "true" : "false"}</p>
<p>isPause: {isPause ? "true" : "false"}</p>
<button onClick={play}>play</button>
<button onClick={pause}>pause</button>
</>
);
}

export default App;