Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loading songs into a playlist #14

Open
kyoukhana opened this issue Jul 17, 2020 · 3 comments
Open

loading songs into a playlist #14

kyoukhana opened this issue Jul 17, 2020 · 3 comments

Comments

@kyoukhana
Copy link

Is it possible to load songs into a play list dynamically so that i can also add additional songs. Something like this below. Also each song that is being loaded or added to the list later would have a percentage loaded so can display to the user when its ready to play or even play all tracks at same time.

{
		"name": "Song Name 3",
		"artist": "Artist Name",
		"album": "Album Name",
		"url": "/song/url.mp3",
		"cover_art_url": "/cover/art/url.jpg",
    		"time_callbacks": {
      			1: function(){
        			console.log( "1 second into the song" )
      			},
      			90: function(){
        			console.log( "1 minute 30 seconds into the song" );
      			},
      			110: function(){
        			console.log( "1 minute 50 seconds into the song" );
      			}
    		}
	}
@vanand-conga
Copy link
Contributor

Yeah, you can do that. I would start with creating classes like Album and PlayList.

Some pseudo code.

class Album {
   name = null;
   artist = null;
   url = null;
   cover_image = null;
   ...

   loaded = false;
   buzzId = null;
   
   constructor(name, artist, url, cover_image, ...) {
      this.name = name;
      this.artist = artist;
      ...

     $buzz.register(this.url, this.name);
   }

    load(): Promise {
      return $buzz.load(this.url);
    }

    play() {
       this.buzzId = $buzz.play(this.url);
    }

    stop() {
       $buzz.stop(this.buzzId);
    }

    ....
}

class PlayList {

   queue = []; // Array of albums

   currentPlaying = 0;

   constructor(albums) {
      this.queue = albums;
   }

   addAlbum(album) {
      this.queue.add(album)
   }

   play() {
      this.albums[this.currentPlaying].play();
   }

   stop() {
      this.albums[this.currentPlaying].stop();
   }

    next() {
       this.currentPlaying++;
       this.stop();
       this.play();
   }

   ....
}

I hope you got some idea.

@kyoukhana
Copy link
Author

is it possible to play all the tracks in the playlist ad the same time.

@kyoukhana
Copy link
Author

Here is some Pseudo code I have as well I am using VueJS

mounted: function(){
  
  $buzz.setup(); // you need to call setup before doing anything in global level.

            var promise = $buzz.load('/api/user/track/audio/9?token='+this.$auth.token());

            promise.then(function(evt) {
                console.log('All audio resources are loaded');
                console.log(evt);
            });
}
methods:{
   addTrack(){
       var audioURL='/api/user/track/audio/'+track.trackID+'?token='+this.$auth.token();
      $buzz.register(audioURL, track.trackID); 
  }

 play(){
    $buzz.play();
  }

}

But the $buzz.play would be good if its a master play button to play all the tracks loaded in the object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants