Skip to content

Commit 36ec04f

Browse files
feat: finish all the functionalities of thr player
1 parent d38f956 commit 36ec04f

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

src/App.vue

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
</header>
66
<main>
77
<section class="player">
8-
<h2 class="song-title"></h2>
8+
<h2 class="song-title">{{ current.title }} <span>{{ current.artist }}</span></h2>
9+
<div class="control">
10+
<button class="prev" @click="previous">Previous</button>
11+
<button class="play" v-if="!isPlaying" @click="play">Play</button>
12+
<button class="pause" v-else @click="pause">Pause</button>
13+
<button class="next" @click="next">Next</button>
14+
</div>
15+
</section>
16+
<section class="playlist">
17+
<h3>The Playlist</h3>
18+
<button v-for="song in songs" :key="song.src" @click="play(song)" :class="(song.src == current.src) ? 'song playing' : 'song'">
19+
{{ song.title }} - {{ song.artist}}
20+
</button>
921
</section>
1022
</main>
1123
</div>
@@ -15,7 +27,61 @@
1527
1628
export default {
1729
name: 'App',
18-
30+
data () {
31+
return {
32+
current: {},
33+
index: 0,
34+
isPlaying : false,
35+
songs: [
36+
{
37+
title : 'Suragana Kirilliye',
38+
artist: 'Infaass',
39+
src : require('./assets/Suragana-Kirilliye-(Remix)-Infaas-Nooruddin.mp3')
40+
},
41+
{
42+
title : 'Yannada Igilli',
43+
artist: 'Infaass',
44+
src : require('./assets/iraj_get-gone-luca-dayz-iraj-ft-carlprit.mp3')
45+
},
46+
],
47+
player: new Audio()
48+
}
49+
},
50+
methods: {
51+
play (song) {
52+
if (typeof song.src != "undefined") {
53+
this.current = song;
54+
this.player.src = this.current.src;
55+
}
56+
this.player.play();
57+
this.isPlaying = true;
58+
},
59+
pause (){
60+
this.player.pause();
61+
this.isPlaying = false;
62+
},
63+
next(){
64+
this.index++;
65+
if(this.index > this.songs.lenght - 1){
66+
this.index = 0;
67+
}
68+
this.current = this.songs[this.index];
69+
this.play[this.current];
70+
},
71+
previous(){
72+
this.index--;
73+
if(this.index < 0){
74+
this.index = this.songs.lenght - 1;
75+
}
76+
this.current = this.songs[this.index];
77+
this.play[this.current];
78+
}
79+
},
80+
created() {
81+
this.current = this.songs[this.index];
82+
this.player.src = this.current.src;
83+
84+
}
1985
}
2086
</script>
2187

@@ -34,6 +100,6 @@ header{
34100
align-item:center;
35101
padding: 15px;
36102
background-color: #212121;
37-
color:#fff;
103+
color:#fff;
38104
}
39105
</style>

0 commit comments

Comments
 (0)