generated from aura-nw/aura-reactjs-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
19 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useEffect, useRef } from 'react' | ||
|
||
const BackgroundAudio = () => { | ||
const audioRef = useRef(null) | ||
|
||
useEffect(() => { | ||
const handleUserInteraction = () => { | ||
const audio = audioRef.current | ||
if (audio) { | ||
audio.play().catch((err) => console.log('Autoplay failed:', err)) | ||
} | ||
// Remove event listener after first interaction | ||
document.removeEventListener('click', handleUserInteraction) | ||
} | ||
|
||
// Wait for user interaction | ||
document.addEventListener('click', handleUserInteraction) | ||
|
||
return () => { | ||
document.removeEventListener('click', handleUserInteraction) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<audio ref={audioRef} loop autoPlay> | ||
<source src='/assets/audio/ava-background.mp3' type='audio/mpeg' /> | ||
Your browser does not support the audio element. | ||
</audio> | ||
) | ||
} | ||
|
||
export default BackgroundAudio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters