Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Bg Music #27

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading