Skip to content

Commit

Permalink
Merge pull request #27 from bhavyaKhatri2703/main
Browse files Browse the repository at this point in the history
Added Bg Music
  • Loading branch information
bhavyaKhatri2703 authored Sep 19, 2024
2 parents 8241ff1 + 3b36aa5 commit e0dd6f3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
Binary file added frontend/public/BgMusic.mp3
Binary file not shown.
Binary file added frontend/public/muteAudio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/playAudio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions frontend/src/components/Audio/AudioPlayer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useState, useRef } from "react";
import playIcon from "../../../public/playAudio.png"; // Adjust the path as needed
import muteIcon from "../../../public/muteAudio.png"; // Adjust the path as needed
import audioFile from "../../../public/BgMusic.mp3"; // Adjust the path as needed

const AudioControl = () => {
const [isPlaying, setIsPlaying] = useState(false);
const audioRef = useRef<HTMLAudioElement>(null);

const toggleAudio = () => {
const audio = audioRef.current;
if (audio) {
if (isPlaying) {
audio.pause();
} else {
audio.play();
}
setIsPlaying(!isPlaying);
}
};

return (
<div className="fixed bottom-4 right-6">
<button
onClick={toggleAudio}
className="bg-transparent border-none p-0 m-0 rounded-full mt-4"
>
<img
src={isPlaying ? playIcon : muteIcon}
alt={isPlaying ? "play" : "mute"}
className="w-12 h-12"
/>
</button>
<audio ref={audioRef} src={audioFile} loop />
</div>
);
};

export default AudioControl;
2 changes: 2 additions & 0 deletions frontend/src/components/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import p5 from "../../../public/p5.png";
import p6 from "../../../public/p6.png";
import p7 from "../../../public/p7.png";
import p8 from "../../../public/p8.png";
import AudioControl from "../Audio/AudioPlayer";

const pokemonImages = [p1, p2, p3, p4, p5, p6, p7, p8];

Expand All @@ -25,6 +26,7 @@ const Home = () => {
<a href="/Tutorial" className="text-white gba text-xl">
How to contribute
</a>
<AudioControl/>
</div>
);
};
Expand Down

0 comments on commit e0dd6f3

Please sign in to comment.