teodorpatras / Jukebox

Player for streaming local and remote audio files. Written in Swift.
MIT License
551 stars 122 forks source link

it takes time adding http extensions to jukebox player #81

Open firatyenidunya opened 7 years ago

firatyenidunya commented 7 years ago

I am getting mp3 files from server. And there is al lot of mp3 files that are appended to jukebox player and it takes a lot of time. for example I am getting 25 music files I am adding them to jukebox player via for loop. It takes at least 20 seconds. Any suggestions? my code,

 for index in 0...self.musicInfo.count-1{
  JukeBoxManager.sharedInstance.jukebox.append(item: JukeboxItem (URL: URL(string: self.musicInfo[index].url)!), loadingAssets: true)
}
RajChanchal commented 7 years ago

It did also happen with me, what I did was, manage my own playlist array and keep track of next previous song. When one finishes, I start playing the next from my tracked playlist. Didn't get time to figure our why Jukebox is slow.

firatyenidunya commented 7 years ago

How did you do that? Can you help me?

RajChanchal commented 7 years ago

Yes, sure. In my SongsPlayerViewController, I defined a property like: private var playlist:Array<Song>! Wrote a method in the same class as: func playSongs(list:Array<Song>,indexToPlay:Int) Whenever I need to play multiple songs, I just call this method. This method, in its definition, assigns the instance property playlist with list parameter of the method. The definition of this method does also initialises Jukebox instance with only song item (selects the one based on indexToPlay from the list array) and calls Jukebox's play method.

When the progress of the current song reaches 1, you can call the same playSongs method with next song index and same playlist array.

if(currentSongIndex<playlist.count-1){
     currentSongIndex += 1
     _=self.playList(list: playlist, indexToPlay: currentSongIndex,playingNewPlaylist:false)
}

Let me know if you feel difficulty somewhere. I am using Jukebox's delegate method: jukeboxPlaybackProgressDidChange(_ jukebox : Jukebox) to track progress. jukeboxDidLoadItem( is not handy for playing the next song, I had to use progress method.

firatyenidunya commented 7 years ago

I'll try. Thanks a lot!