Skip to content

Commit

Permalink
feat(player): play next song continuously #7
Browse files Browse the repository at this point in the history
  • Loading branch information
rudywaltz committed Mar 10, 2019
1 parent ddaa68e commit be9388f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
20 changes: 20 additions & 0 deletions cypress/integration/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,25 @@ describe('player', () => {
})
});

it('play next sound continously', () => {
cy.setStorage('song', {});
cy.setStorage('playlist', [{
title: 'Jézus és a jelzőrakéta',
url: '/jezusesajelzoraketa.mp3'
}, {
title: 'Jézus és a jelzőrakéta111111',
url: '/jezusesajelzoraketa.mp3'
}])
cy.get('#player .player__play')
.click()
cy.get('#player .player__seek')
.click()
.click()
.click()
.click()
.click()
.click()
cy.get('.player__title').contains('Jézus és a jelzőrakéta111111')
});
});
});
20 changes: 11 additions & 9 deletions src/components/Player.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ <h3 class="player__url">{ $song.url ? $song.url : 'No sound selected' }</h3>
},
onload: () => {
this.set({duration: this.currentSound.duration()});
const { playing } = this.get();
if (playing) {
this.playSound();
}
}
});
}
Expand All @@ -75,27 +79,25 @@ <h3 class="player__url">{ $song.url ? $song.url : 'No sound selected' }</h3>
methods: {
toggleSound: function() {
const { playing } = this.get();
if(playing) {
this.stopSound();
} else {
this.playSound()
}
playing ? this.stopSound() : this.playSound();
},

playSound: function() {
this.currentSound.play();
const interval = setInterval(() => {
const playing = this.currentSound.playing();
this.set({ playing });

if(!playing) {
this.set({time: 0 });
clearInterval(interval);
} else {
if(playing) {
this.set({duration: this.currentSound.duration()});
this.set({time: this.currentSound.seek()});
} else {
this.set({time: 0 });
clearInterval(interval);
}
}, 200);
},

stopSound: function() {
this.currentSound.stop();
this.set({playing: this.currentSound.playing()});
Expand Down
11 changes: 2 additions & 9 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@ polka() // You can also use Express
store: request => {
return new Store({
development: dev,
song: {
title: 'Jézus és a jelzőrakéta',
url: '/jezusesajelzoraketa.mp3'
},
playlist: [{
title: 'Jézus és a jelzőrakéta',
url: '/jezusesajelzoraketa.mp3',
duration: 346
}]
song: {},
playlist: []
})
}
})
Expand Down

0 comments on commit be9388f

Please sign in to comment.