├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
└── src
├── App.js
├── assets
├── covers
│ ├── Aiguille.jpg
│ ├── CanaryForest.jpg
│ └── Sworn.jpg
└── songs
│ ├── Beaver Creek.mp3
│ ├── Daylight.mp3
│ ├── Keep Going.mp3
│ ├── Nightfall.mp3
│ ├── Reflection.mp3
│ └── Under the City Stars.mp3
├── components
├── Library.js
├── LibrarySong.js
├── Nav.js
├── Player.js
└── Song.js
├── data.js
├── index.js
├── serviceWorker.js
├── styles
├── _library.scss
├── _nav.scss
├── _player.scss
├── _song.scss
└── app.scss
└── util.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2 |
3 | ## Available Scripts
4 |
5 | In the project directory, you can run:
6 |
7 | ### `npm start`
8 |
9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11 |
12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console.
14 |
15 | ### `npm test`
16 |
17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19 |
20 | ### `npm run build`
21 |
22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance.
24 |
25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed!
27 |
28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29 |
30 | ### `npm run eject`
31 |
32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33 |
34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35 |
36 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37 |
38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39 |
40 | ## Learn More
41 |
42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43 |
44 | To learn React, check out the [React documentation](https://reactjs.org/).
45 |
46 | ### Code Splitting
47 |
48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49 |
50 | ### Analyzing the Bundle Size
51 |
52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53 |
54 | ### Making a Progressive Web App
55 |
56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57 |
58 | ### Advanced Configuration
59 |
60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61 |
62 | ### Deployment
63 |
64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65 |
66 | ### `npm run build` fails to minify
67 |
68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
69 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "music-player",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@fortawesome/fontawesome-svg-core": "^1.2.30",
7 | "@fortawesome/free-solid-svg-icons": "^5.14.0",
8 | "@fortawesome/react-fontawesome": "^0.1.11",
9 | "@testing-library/jest-dom": "^4.2.4",
10 | "@testing-library/react": "^9.5.0",
11 | "@testing-library/user-event": "^7.2.1",
12 | "node-sass": "^4.14.1",
13 | "react": "^16.13.1",
14 | "react-dom": "^16.13.1",
15 | "react-scripts": "^4.0.0",
16 | "uuid": "^8.3.0"
17 | },
18 | "scripts": {
19 | "start": "react-scripts start",
20 | "build": "react-scripts build",
21 | "test": "react-scripts test",
22 | "eject": "react-scripts eject"
23 | },
24 | "eslintConfig": {
25 | "extends": "react-app"
26 | },
27 | "browserslist": {
28 | "production": [
29 | ">0.2%",
30 | "not dead",
31 | "not op_mini all"
32 | ],
33 | "development": [
34 | "last 1 chrome version",
35 | "last 1 firefox version",
36 | "last 1 safari version"
37 | ]
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
12 |
16 |
17 |
21 |
22 |
31 | React App
32 |
33 |
34 | You need to enable JavaScript to run this app.
35 |
36 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/public/logo512.png
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useRef } from "react";
2 | import "./styles/app.scss";
3 | //Import Components
4 | import Player from "./components/Player";
5 | import Song from "./components/Song";
6 | import Library from "./components/Library";
7 | import Nav from "./components/Nav";
8 | //Import data
9 | import chillhop from "./data";
10 | //Util
11 | import { playAudio } from "./util";
12 |
13 | function App() {
14 | //Ref
15 | const audioRef = useRef(null);
16 |
17 | const [songs, setSongs] = useState(chillhop());
18 | const [currentSong, setCurrentSong] = useState(songs[0]);
19 | const [isPlaying, setIsPlaying] = useState(false);
20 | const [songInfo, setSongInfo] = useState({
21 | currentTime: 0,
22 | duration: 0,
23 | animationPercentage: 0,
24 | volume: 0,
25 | });
26 | const [libraryStatus, setLibraryStatus] = useState(false);
27 |
28 | const timeUpdateHandler = (e) => {
29 | const current = e.target.currentTime;
30 | const duration = e.target.duration;
31 |
32 | const roundedCurrent = Math.round(current);
33 | const roundedDuration = Math.round(duration);
34 | const percentage = Math.round((roundedCurrent / roundedDuration) * 100);
35 | setSongInfo({
36 | ...songInfo,
37 | currentTime: current,
38 | duration: duration,
39 | animationPercentage: percentage,
40 | volume: e.target.volume,
41 | });
42 | };
43 | const songEndHandler = async () => {
44 | let currentIndex = songs.findIndex((song) => song.id === currentSong.id);
45 | await setCurrentSong(songs[(currentIndex + 1) % songs.length]);
46 | playAudio(isPlaying, audioRef);
47 | return;
48 | };
49 | return (
50 |
51 |
52 |
53 |
64 |
72 |
80 |
81 | );
82 | }
83 |
84 | export default App;
85 |
--------------------------------------------------------------------------------
/src/assets/covers/Aiguille.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/src/assets/covers/Aiguille.jpg
--------------------------------------------------------------------------------
/src/assets/covers/CanaryForest.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/src/assets/covers/CanaryForest.jpg
--------------------------------------------------------------------------------
/src/assets/covers/Sworn.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/src/assets/covers/Sworn.jpg
--------------------------------------------------------------------------------
/src/assets/songs/Beaver Creek.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/src/assets/songs/Beaver Creek.mp3
--------------------------------------------------------------------------------
/src/assets/songs/Daylight.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/src/assets/songs/Daylight.mp3
--------------------------------------------------------------------------------
/src/assets/songs/Keep Going.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/src/assets/songs/Keep Going.mp3
--------------------------------------------------------------------------------
/src/assets/songs/Nightfall.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/src/assets/songs/Nightfall.mp3
--------------------------------------------------------------------------------
/src/assets/songs/Reflection.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/src/assets/songs/Reflection.mp3
--------------------------------------------------------------------------------
/src/assets/songs/Under the City Stars.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/developedbyed/music-player-react/a001ac45001b2e11cf380a899ba704787ff38ae5/src/assets/songs/Under the City Stars.mp3
--------------------------------------------------------------------------------
/src/components/Library.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | import LibrarySong from "./LibrarySong";
4 |
5 | const Library = ({
6 | songs,
7 | setCurrentSong,
8 | audioRef,
9 | isPlaying,
10 | setSongs,
11 | libraryStatus,
12 | }) => {
13 | return (
14 |
15 |
Library
16 |
17 | {songs.map((song) => (
18 |
31 | ))}
32 |
33 |
34 | );
35 | };
36 |
37 | export default Library;
38 |
--------------------------------------------------------------------------------
/src/components/LibrarySong.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { playAudio } from "../util";
3 |
4 | const LibrarySong = ({
5 | name,
6 | artist,
7 | cover,
8 | id,
9 | setCurrentSong,
10 | songs,
11 | audioRef,
12 | isPlaying,
13 | setSongs,
14 | active,
15 | }) => {
16 | const songSelectHandler = () => {
17 | const selectedSong = songs.filter((state) => state.id === id);
18 | setCurrentSong({ ...selectedSong[0] });
19 | //Set Active in library
20 | const newSongs = songs.map((song) => {
21 | if (song.id === id) {
22 | return {
23 | ...song,
24 | active: true,
25 | };
26 | } else {
27 | return {
28 | ...song,
29 | active: false,
30 | };
31 | }
32 | });
33 | setSongs(newSongs);
34 |
35 | //Play audio
36 | playAudio(isPlaying, audioRef);
37 | };
38 | return (
39 |
43 |
44 |
45 |
{name}
46 | {artist}
47 |
48 |
49 | );
50 | };
51 |
52 | export default LibrarySong;
53 |
--------------------------------------------------------------------------------
/src/components/Nav.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
3 | import { faMusic } from "@fortawesome/free-solid-svg-icons";
4 |
5 | const Nav = ({ setLibraryStatus, libraryStatus }) => {
6 | const openLibraryHandler = () => {
7 | setLibraryStatus(!libraryStatus);
8 | };
9 |
10 | return (
11 |
12 | Waves
13 |
17 | Library
18 |
19 |
20 |
21 | );
22 | };
23 |
24 | export default Nav;
25 |
--------------------------------------------------------------------------------
/src/components/Player.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from "react";
2 | import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
3 | import {
4 | faPlay,
5 | faAngleLeft,
6 | faAngleRight,
7 | faPause,
8 | faVolumeDown,
9 | } from "@fortawesome/free-solid-svg-icons";
10 |
11 | import { playAudio } from "../util";
12 |
13 | const Player = ({
14 | isPlaying,
15 | setIsPlaying,
16 | audioRef,
17 | songInfo,
18 | setSongInfo,
19 | currentSong,
20 | songs,
21 | setCurrentSong,
22 | setSongs,
23 | }) => {
24 | const [activeVolume, setActiveVolume] = useState(false);
25 | //UseEffect Update List
26 | const activeLibraryHandler = (nextPrev) => {
27 | const newSongs = songs.map((song) => {
28 | if (song.id === nextPrev.id) {
29 | return {
30 | ...song,
31 | active: true,
32 | };
33 | } else {
34 | return {
35 | ...song,
36 | active: false,
37 | };
38 | }
39 | });
40 |
41 | setSongs(newSongs);
42 | };
43 |
44 | const trackAnim = {
45 | transform: `translateX(${songInfo.animationPercentage}%)`,
46 | };
47 | //Event Handlers
48 | function getTime(time) {
49 | return (
50 | Math.floor(time / 60) + ":" + ("0" + Math.floor(time % 60)).slice(-2)
51 | );
52 | }
53 | const dragHandler = (e) => {
54 | audioRef.current.currentTime = e.target.value;
55 | setSongInfo({ ...songInfo, currentTime: e.target.value });
56 | };
57 |
58 | const playSongHandler = () => {
59 | if (isPlaying) {
60 | audioRef.current.pause();
61 | setIsPlaying(!isPlaying);
62 | } else {
63 | audioRef.current.play();
64 | setIsPlaying(!isPlaying);
65 | }
66 | };
67 | const skipTrackHandler = async (direction) => {
68 | let currentIndex = songs.findIndex((song) => song.id === currentSong.id);
69 |
70 | //Forward BAck
71 | if (direction === "skip-forward") {
72 | await setCurrentSong(songs[(currentIndex + 1) % songs.length]);
73 | activeLibraryHandler(songs[(currentIndex + 1) % songs.length]);
74 | }
75 | if (direction === "skip-back") {
76 | if ((currentIndex - 1) % songs.length === -1) {
77 | await setCurrentSong(songs[songs.length - 1]);
78 | activeLibraryHandler(songs[songs.length - 1]);
79 | playAudio(isPlaying, audioRef);
80 | return;
81 | }
82 | await setCurrentSong(songs[(currentIndex - 1) % songs.length]);
83 | activeLibraryHandler(songs[(currentIndex - 1) % songs.length]);
84 | }
85 | if (isPlaying) audioRef.current.play();
86 | };
87 | const changeVolume = (e) => {
88 | let value = e.target.value;
89 | audioRef.current.volume = value;
90 | setSongInfo({ ...songInfo, volume: value });
91 | };
92 |
93 | return (
94 |
95 |
96 |
{getTime(songInfo.currentTime)}
97 |
112 |
{songInfo.duration ? getTime(songInfo.duration) : "0:00"}
113 |
114 |
115 | skipTrackHandler("skip-back")}
117 | className="skip-back"
118 | size="2x"
119 | icon={faAngleLeft}
120 | />
121 |
127 | skipTrackHandler("skip-forward")}
132 | />
133 | setActiveVolume(!activeVolume)}
135 | icon={faVolumeDown}
136 | />
137 | {activeVolume && (
138 |
146 | )}
147 |
148 |
149 | );
150 | };
151 |
152 | export default Player;
153 |
--------------------------------------------------------------------------------
/src/components/Song.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | const Song = ({ currentSong, isPlaying }) => {
4 | return (
5 |
6 |
11 |
{currentSong.name}
12 |
{currentSong.artist}
13 |
14 | );
15 | };
16 |
17 | export default Song;
18 |
--------------------------------------------------------------------------------
/src/data.js:
--------------------------------------------------------------------------------
1 | import { v4 as uuidv4 } from "uuid";
2 | function chillHop() {
3 | return [
4 | {
5 | name: "Beaver Creek",
6 | cover:
7 | "https://chillhop.com/wp-content/uploads/2020/09/0255e8b8c74c90d4a27c594b3452b2daafae608d-1024x1024.jpg",
8 | artist: "Aso, Middle School, Aviino",
9 | audio: "https://mp3.chillhop.com/serve.php/?mp3=10075",
10 | color: ["#205950", "#2ab3bf"],
11 | id: uuidv4(),
12 | active: true,
13 | },
14 | {
15 | name: "Daylight",
16 | cover:
17 | "https://chillhop.com/wp-content/uploads/2020/07/ef95e219a44869318b7806e9f0f794a1f9c451e4-1024x1024.jpg",
18 | artist: "Aiguille",
19 | audio: "https://mp3.chillhop.com/serve.php/?mp3=9272",
20 | color: ["#EF8EA9", "#ab417f"],
21 | id: uuidv4(),
22 | active: false,
23 | },
24 | {
25 | name: "Keep Going",
26 | cover:
27 | "https://chillhop.com/wp-content/uploads/2020/07/ff35dede32321a8aa0953809812941bcf8a6bd35-1024x1024.jpg",
28 | artist: "Swørn",
29 | audio: "https://mp3.chillhop.com/serve.php/?mp3=9222",
30 | color: ["#CD607D", "#c94043"],
31 | id: uuidv4(),
32 | active: false,
33 | },
34 | {
35 | name: "Nightfall",
36 | cover:
37 | "https://chillhop.com/wp-content/uploads/2020/07/ef95e219a44869318b7806e9f0f794a1f9c451e4-1024x1024.jpg",
38 | artist: "Aiguille",
39 | audio: "https://mp3.chillhop.com/serve.php/?mp3=9148",
40 | color: ["#EF8EA9", "#ab417f"],
41 | id: uuidv4(),
42 | active: false,
43 | },
44 | {
45 | name: "Reflection",
46 | cover:
47 | "https://chillhop.com/wp-content/uploads/2020/07/ff35dede32321a8aa0953809812941bcf8a6bd35-1024x1024.jpg",
48 | artist: "Swørn",
49 | audio: "https://mp3.chillhop.com/serve.php/?mp3=9228",
50 | color: ["#CD607D", "#c94043"],
51 | id: uuidv4(),
52 | active: false,
53 | },
54 | {
55 | name: "Under the City Stars",
56 | cover:
57 | "https://chillhop.com/wp-content/uploads/2020/09/0255e8b8c74c90d4a27c594b3452b2daafae608d-1024x1024.jpg",
58 | artist: "Aso, Middle School, Aviino",
59 | audio: "https://mp3.chillhop.com/serve.php/?mp3=10074",
60 | color: ["#205950", "#2ab3bf"],
61 | id: uuidv4(),
62 | active: false,
63 | },
64 | //ADD MORE HERE
65 | ];
66 | }
67 |
68 | export default chillHop;
69 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 | import App from "./App";
4 | import * as serviceWorker from "./serviceWorker";
5 |
6 | ReactDOM.render(
7 |
8 |
9 | ,
10 | document.getElementById("root")
11 | );
12 |
13 | // If you want your app to work offline and load faster, you can change
14 | // unregister() to register() below. Note this comes with some pitfalls.
15 | // Learn more about service workers: https://bit.ly/CRA-PWA
16 | serviceWorker.unregister();
17 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.0/8 are considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl, {
104 | headers: { 'Service-Worker': 'script' },
105 | })
106 | .then(response => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get('content-type');
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf('javascript') === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then(registration => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | 'No internet connection found. App is running in offline mode.'
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ('serviceWorker' in navigator) {
133 | navigator.serviceWorker.ready
134 | .then(registration => {
135 | registration.unregister();
136 | })
137 | .catch(error => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/styles/_library.scss:
--------------------------------------------------------------------------------
1 | .library {
2 | position: fixed;
3 | box-shadow: 2px 2px 50px rgb(221, 221, 221);
4 | border-radius: 1rem;
5 | top: 0;
6 | left: 0;
7 | width: 20rem;
8 | height: 100%;
9 | overflow: scroll;
10 | background: white;
11 | transform: translateX(-100%);
12 | transition: all 0.5s ease;
13 | opacity: 0;
14 |
15 | h2 {
16 | padding: 2rem;
17 | }
18 | }
19 |
20 | .library-song {
21 | display: flex;
22 | align-items: center;
23 | padding: 1rem 2rem 1rem 2rem;
24 | cursor: pointer;
25 | transition: all 0.75s ease-out;
26 |
27 | img {
28 | width: 30%;
29 | }
30 | &:hover {
31 | background: rgb(235, 235, 235);
32 | }
33 | }
34 | .song-description {
35 | padding-left: 1rem;
36 | h3 {
37 | font-size: 1rem;
38 | }
39 | h4 {
40 | font-size: 0.7rem;
41 | }
42 | }
43 |
44 | /* The emerging W3C standard
45 | that is currently Firefox-only */
46 | * {
47 | scrollbar-width: thin;
48 | scrollbar-color: rgba(155, 155, 155, 0.7) transparent;
49 | }
50 |
51 | /* Works on Chrome/Edge/Safari */
52 | *::-webkit-scrollbar {
53 | width: 5px;
54 | }
55 | *::-webkit-scrollbar-track {
56 | background: transparent;
57 | }
58 | *::-webkit-scrollbar-thumb {
59 | background-color: rgba(155, 155, 155, 0.7);
60 | border-radius: 20px;
61 | border: transparent;
62 | }
63 |
64 | .selected {
65 | background: rgb(194, 208, 253);
66 | }
67 | .active-library {
68 | transform: translateX(0%);
69 | opacity: 1;
70 | }
71 |
72 | @media screen and (max-width: 768px) {
73 | .library {
74 | width: 100%;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/styles/_nav.scss:
--------------------------------------------------------------------------------
1 | nav {
2 | min-height: 10vh;
3 | display: flex;
4 | justify-content: space-around;
5 | align-items: center;
6 | button {
7 | background: transparent;
8 | border: none;
9 | cursor: pointer;
10 | padding: 0.5rem;
11 | border: 2px solid rgb(65, 65, 65);
12 | transition: all 0.3s ease;
13 | &:hover {
14 | background: rgb(65, 65, 65);
15 | color: white;
16 | }
17 | }
18 | .library-active {
19 | background: rgb(65, 65, 65);
20 | color: white;
21 | }
22 | }
23 |
24 | @media screen and (max-width: 768px) {
25 | nav {
26 | button {
27 | z-index: 10;
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/styles/_player.scss:
--------------------------------------------------------------------------------
1 | .player {
2 | min-height: 20vh;
3 | display: flex;
4 | flex-direction: column;
5 | align-items: center;
6 | justify-content: space-between;
7 | }
8 |
9 | .time-control {
10 | width: 50%;
11 | display: flex;
12 | align-items: center;
13 | input {
14 | width: 100%;
15 | -webkit-appearance: none;
16 | background: transparent;
17 | cursor: pointer;
18 | }
19 |
20 | p {
21 | padding: 1rem;
22 | }
23 | }
24 | .play-control {
25 | display: flex;
26 | justify-content: space-between;
27 | align-items: center;
28 | padding: 1rem;
29 |
30 | width: 40%;
31 | svg {
32 | cursor: pointer;
33 | }
34 | }
35 |
36 | .track {
37 | width: 100%;
38 | height: 1rem;
39 | position: relative;
40 | overflow: hidden;
41 | border-radius: 1rem;
42 | }
43 | .animate-track {
44 | background: rgb(204, 204, 204);
45 | width: 100%;
46 | height: 100%;
47 | position: absolute;
48 | top: 0;
49 | left: 0;
50 | transform: translateX(0%);
51 | padding: 1rem;
52 | pointer-events: none;
53 | }
54 |
55 | input[type="range"]:focus {
56 | outline: none;
57 | }
58 | input[type="range"]::-webkit-slider-thumb {
59 | -webkit-appearance: none;
60 | height: 16px;
61 | width: 16px;
62 | }
63 |
64 | @media screen and (max-width: 768px) {
65 | .time-control {
66 | width: 90%;
67 | }
68 | .play-control {
69 | width: 80%;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/styles/_song.scss:
--------------------------------------------------------------------------------
1 | .song-container {
2 | min-height: 60vh;
3 | display: flex;
4 | flex-direction: column;
5 | justify-content: center;
6 | align-items: center;
7 | img {
8 | width: 25%;
9 | border-radius: 50%;
10 | transition: all 2s ease;
11 | }
12 | h2 {
13 | padding: 3rem 1rem 1rem 1rem;
14 | }
15 | h3 {
16 | font-size: 1rem;
17 | }
18 | }
19 |
20 | @media screen and (max-width: 768px) {
21 | .song-container {
22 | img {
23 | width: 60%;
24 | }
25 | }
26 | }
27 |
28 | @keyframes rotate {
29 | from {
30 | transform: rotate(0deg);
31 | }
32 | to {
33 | transform: rotate(360deg);
34 | }
35 | }
36 |
37 | .rotateSong {
38 | animation: rotate 20s linear forwards infinite;
39 | }
40 |
--------------------------------------------------------------------------------
/src/styles/app.scss:
--------------------------------------------------------------------------------
1 | * {
2 | margin: 0;
3 | padding: 0;
4 | box-sizing: border-box;
5 | }
6 |
7 | body {
8 | font-family: "Lato", sans-serif;
9 | }
10 | .App {
11 | transition: all 0.5s ease;
12 | }
13 | .library-active {
14 | margin-left: 30%;
15 | }
16 |
17 | h1 {
18 | font-size: 1rem;
19 | }
20 | h2 {
21 | color: rgb(51, 51, 51);
22 | }
23 | h3,
24 | h4 {
25 | color: rgb(100, 100, 100);
26 | font-weight: 400;
27 | }
28 |
29 | @import "./song";
30 | @import "./player";
31 | @import "./library";
32 | @import "./nav";
33 |
--------------------------------------------------------------------------------
/src/util.js:
--------------------------------------------------------------------------------
1 | export const playAudio = (isPlaying, audioRef) => {
2 | if (isPlaying) {
3 | const playPromise = audioRef.current.play();
4 | if (playPromise !== undefined) {
5 | playPromise
6 | .then((audio) => {
7 | audioRef.current.play();
8 | })
9 | .catch((error) => console.log(error));
10 | }
11 | }
12 | };
13 |
--------------------------------------------------------------------------------