Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Player {
- constructor () {
- this.currentlyPlaying = album.songs[0];
- this.playState = 'stopped';
- this.volume = 80;
- this.soundObject = new buzz.sound(this.currentlyPlaying.soundFileUrl);
- }
- getDuration() {
- return this.soundObject.getDuration();
- }
- getTime() {
- return this.soundObject.getTime();
- }
- playPause (song = this.currentlyPlaying) {
- if (this.currentlyPlaying !== song) {
- // Stop the currently playing sound file (even if nothing is playing)
- this.soundObject.stop();
- // Clear classes on the song that's currently playing
- this.currentlyPlaying.element.removeClass('playing paused');
- // Update our currentlyPlaying and playState properties
- this.currentlyPlaying = song;
- this.playState = 'stopped';
- this.soundObject = new buzz.sound(this.currentlyPlaying.soundFileUrl);
- }
- if (this.playState === 'paused' || this.playState === 'stopped') {
- this.soundObject.setVolume( this.volume );
- this.soundObject.play();
- this.playState = 'playing';
- this.currentlyPlaying.element.removeClass('paused').addClass('playing');
- } else {
- this.soundObject.pause();
- this.playState = 'paused';
- this.currentlyPlaying.element.removeClass('playing').addClass('paused');
- }
- }
- skipTo (percent) {
- if (this.playState !== 'playing') { return }
- this.soundObject.setTime( (percent / 100) * this.soundObject.getDuration() );
- }
- setVolume (percent) {
- this.volume = percent;
- this.soundObject.setVolume(percent);
- }
- prettyTime (timeInSeconds) {
- this.ptime = Math.floor(timeInSeconds);
- }
- }
- const player = new Player();
Add Comment
Please, Sign In to add comment