Skip to content

Commit

Permalink
complete play mode feature and add some songs
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamadadithya committed Jul 10, 2022
1 parent d4b3441 commit 8825410
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 16 deletions.
38 changes: 37 additions & 1 deletion src/data/songs.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,41 @@ export const songs = [
name: 'Let it Bleed',
cover: 'let-it-bleed.jpg'
}
}
},
{
title: 'Planet Caravan',
filename: `${HOSTING_URL}ipkoupcos7hsuph/planet-caravan.mp3?dl=0`,
artist: 'Pantera',
album: {
name: 'Far Beyond Driven',
cover: 'far-beyond-driven.jpeg'
}
},
{
title: 'Ouch',
filename: `${HOSTING_URL}2m2uopq9jskl0jj/ouch.mp3?dl=0`,
artist: 'Bring Me The Horizon',
album: {
name: 'amo',
cover: 'amo.jpeg'
}
},
{
title: 'Zeitgeist',
filename: `${HOSTING_URL}udwou3jm08cuis0/zeitgeist.mp3?dl=0`,
artist: 'Black Sabbath',
album: {
name: '13',
cover: '13.jpeg'
}
},
{
title: 'Friends',
filename: `${HOSTING_URL}zcet6mgfvdwms45/friends.mp3?dl=0`,
artist: 'Led Zeppelin',
album: {
name: 'Led Zeppelin III',
cover: 'led-zeppelin-3.jpeg'
}
},
]
2 changes: 1 addition & 1 deletion src/helpers/song.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ export const showError = () => {
notyf.error('Please pick a song');
}

export const MODE = ['normal', 'random', 'single'];
export const PLAY_MODE = ['normal', 'random', 'single'];
2 changes: 1 addition & 1 deletion src/routes/__layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<style>
main {
padding: 2em;
padding: 1.4em;
max-width: 800px;
margin: 0 auto;
}
Expand Down
54 changes: 42 additions & 12 deletions src/routes/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
albumCover,
album,
isLoaded,
index
index,
playMode
} from '../stores/song';
import SongBar from '../components/SongBar.svelte';
import { songs } from '../data/songs';
import { onEndedSong, showError } from '../helpers/song';
import { onEndedSong, PLAY_MODE, showError } from '../helpers/song';
let time = 0,
muted = false,
Expand All @@ -23,20 +24,30 @@
ended,
slider,
duration,
audio;
audio,
playModeIcon = 'repeat';
onMount(() => {
audio.onended = async () => {
isPlay.set(false);
time = 0;
let nextSong = $index + 1;
index.set(nextSong);
let lastSong = songs.length - 1;
if ($index > lastSong) {
index.set(0);
onEndedSong(0, audio);
if ($playMode === PLAY_MODE[0]) {
let nextSong = $index + 1;
index.set(nextSong);
if ($index > lastSong) {
index.set(0);
onEndedSong(0, audio);
} else {
onEndedSong(nextSong, audio);
}
} else if ($playMode === PLAY_MODE[1]) {
const randomSong = songs[Math.floor(Math.random() * songs.length)];
const randomIndex = songs.indexOf(randomSong);
index.set(randomIndex);
onEndedSong($index, audio);
} else {
onEndedSong(nextSong, audio);
onEndedSong($index, audio);
}
};
});
Expand Down Expand Up @@ -99,6 +110,19 @@
showError();
}
};
const changeMode = () => {
if ($playMode === PLAY_MODE[0]) {
playMode.set(PLAY_MODE[1]);
playModeIcon = 'random';
} else if ($playMode === PLAY_MODE[1]) {
playMode.set(PLAY_MODE[2]);
playModeIcon = 'repeat-1';
} else {
playMode.set(PLAY_MODE[0]);
playModeIcon = 'repeat';
}
};
</script>

<svelte:head>
Expand All @@ -120,9 +144,11 @@
/>
<div class="card__minutes">
<p>{formatDuration(time)}</p>
<!-- {#if $source}
<button type="button"><i class="far fa-fw fa-random" /></button>
{/if} -->
{#if $source}
<button type="button" on:click={changeMode}
><i class="far fa-fw fa-{playModeIcon}" /></button
>
{/if}
<p>{formatDuration(duration)}</p>
</div>
<div class="card__actions">
Expand Down Expand Up @@ -241,6 +267,10 @@
'Open Sans', 'Helvetica Neue', sans-serif;
}
.card .card__minutes > button {
font-size: 1.5rem;
}
.card .card__actions > button {
padding: 1em;
border-radius: 50%;
Expand Down
2 changes: 1 addition & 1 deletion src/stores/song.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export let source = writable(null),
albumCover = writable('album.png'),
isPlay = writable(false),
isLoaded = writable(false),
mode = writable('normal');
playMode = writable('normal');
Binary file added static/img/13.jpeg
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 static/img/amo.jpeg
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 static/img/far-beyond-driven.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 8825410

@vercel
Copy link

@vercel vercel bot commented on 8825410 Jul 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

muzyka – ./

muzyka-mohamadadithya.vercel.app
muzyka.vercel.app
muzyka-git-master-mohamadadithya.vercel.app

Please sign in to comment.