Guest User

Untitled

a guest
May 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. class Player {
  2. constructor () {
  3. this.currentlyPlaying = album.songs[0];
  4. this.playState = 'stopped';
  5. this.volume = 80;
  6. this.soundObject = new buzz.sound(this.currentlyPlaying.soundFileUrl);
  7. }
  8.  
  9. getDuration() {
  10. return this.soundObject.getDuration();
  11. }
  12.  
  13. getTime() {
  14. return this.soundObject.getTime();
  15. }
  16.  
  17. playPause (song = this.currentlyPlaying) {
  18. if (this.currentlyPlaying !== song) {
  19. // Stop the currently playing sound file (even if nothing is playing)
  20. this.soundObject.stop();
  21. // Clear classes on the song that's currently playing
  22. this.currentlyPlaying.element.removeClass('playing paused');
  23.  
  24. // Update our currentlyPlaying and playState properties
  25. this.currentlyPlaying = song;
  26. this.playState = 'stopped';
  27. this.soundObject = new buzz.sound(this.currentlyPlaying.soundFileUrl);
  28. }
  29. if (this.playState === 'paused' || this.playState === 'stopped') {
  30. this.soundObject.setVolume( this.volume );
  31. this.soundObject.play();
  32. this.playState = 'playing';
  33. this.currentlyPlaying.element.removeClass('paused').addClass('playing');
  34. } else {
  35. this.soundObject.pause();
  36. this.playState = 'paused';
  37. this.currentlyPlaying.element.removeClass('playing').addClass('paused');
  38. }
  39. }
  40.  
  41. skipTo (percent) {
  42. if (this.playState !== 'playing') { return }
  43. this.soundObject.setTime( (percent / 100) * this.soundObject.getDuration() );
  44. }
  45.  
  46. setVolume (percent) {
  47. this.volume = percent;
  48. this.soundObject.setVolume(percent);
  49. }
  50.  
  51. prettyTime (timeInSeconds) {
  52. this.ptime = Math.floor(timeInSeconds);
  53. }
  54. }
  55.  
  56. const player = new Player();
Add Comment
Please, Sign In to add comment