Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

dealing with dynamic playlists


Hola,

This topic I'm sure has been brought up several times, but I want to additionally add in some more technical questions.

I want to first clarify that I'm primarily using the flash player rather than HTML5, as I'm streaming with HLS.

Also wanting to clarify some differentiations with how jwplayer handles internal events. I'm assuming with the HTML5 player, event dispatching is more explicit, whereas when sending javascript events to the flash player, events get queued up, and then dispatched to the flashplayer somehow? Is this a correct assumption?

__That's my preface, here's the question:__

I made a music player, initially the player doesn't need to play anything until the user decides to play a track from a list of tracks. jwplayer doesn't function with subsequent load()'s if setup() doesn't initially load one (this is seemingly a known "fact")

my solution: load in a dummy track: (syntax highlighted code: https://gist.github.com/moimikey/f2539c262292230e2e83)

```
@player = jwplayer?(@ui.player[0]).setup
playlist: [
title: 'you taste like sunshine dust' # magic key to not fire buffering trigger on start
file: '/assets/audio/dummy.m3u8' # necessary to allow subsequent load()'s. jwplayer bug.
]
```

okay, I load in this dummy track, so I can toy around with this playlist. now, I don't want to load() a new playlist, but instead, remove that dummy track, and append new objects.

I've read people attempting this: (take into consideration that @player === jwplayer('selector')) [gist: https://gist.github.com/moimikey/00a60f50f30de3ed9dbf]

```
playlist = [{ track }, { track }, { track }, ...]
@player.getPlaylist().push(playlist)
```

That won't do anything of any use except create a new instance which I can subsequently use with load(). I don't want to do it... I want to APPEND tracks, not replace.

I looked at Trac, went to that method specifically, and saw that it triggers _callInternal('jwGetPlaylist'). Since I'm dealing with a flash player here, I don't think I would even have access to whatever array it's utilizing to store these tracks? I dug a little through the jwplayer instance and saw stuff in jwplayer.config.playlist, but if I alter that, nothing gets propagated, so that's no dice as well.

Is there a better solution for ALTERING an already loaded playlist rather than having to flush it with a new playlist? Maybe some internal methods or hacky event triggers I can attempt?

Thanks!

7 Community Answers

Ethan Feldman

JW Player Support Agent  
0 rated :

You need to at least load a blank file on inital setup() in order to do this.

v...

User  
0 rated :

well right now that's what i'm doing, but the part the primary issue is being able to dynamically create a playlist.

so blank file is on setup(), subsequently I load in a new playlist (lets say with 5 tracks/streams), and then I want to pop off one of the tracks. the playlist at this point is pretty much just read-only.

is this a dead end then? i'd assume the point of a playlist is for it to _not_ be read-only and allow us to pop/push playlist items.

Ethan Feldman

JW Player Support Agent  
0 rated :

You can pop items into a playlist, I wrote a solution for this here – http://stackoverflow.com/questions/17220793/jwplayer-append-file-to-playlist

<!DOCTYPE html>
<html>
<head>
<title>Add to Playlist</title>
<script type="text/javascript" src="http://www.longtailvideo.com/jwplayer/jwplayer.js"></script>

</head> <body> <div id="container"></div> <script type="text/javascript"> jwplayer("container").setup({ height: 254, width: 720, file: "http://content.bitsontherun.com/videos/nPripu9l-60830.mp4", image: "http://content.bitsontherun.com/thumbs/nPripu9l-320.jpg", title: "Big Buck Bunny trailer", listbar: { position: "right", size: 280, }, primary: 'flash' }); function addVideo(videoUrl, videoThumb, videoTitle) { var playlist = jwplayer().getPlaylist(); var newItem = { file: videoUrl, image: videoThumb, title: videoTitle }; playlist.push(newItem); jwplayer().load(playlist); } </script><p>Click on one of the links below to add an item to the player:</p> <ul> <li><a href="#" onclick="addVideo('http://content.bitsontherun.com/videos/yj1shGJB-60830.mp4', 'http://content.bitsontherun.com/thumbs/yj1shGJB-320.jpg', 'Sintel trailer'); return false;">Add the Sintel trailer to the playlist</a></li> <li><a href="#" onclick="addVideo('http://content.bitsontherun.com/videos/i8oQD9zd-kNspJqnJ.mp4', 'http://content.bitsontherun.com/thumbs/i8oQD9zd-640.jpg', 'Tears of Steel'); return false;">Add the Tears of Steel trailer to the playlist</a></li> </ul> </body> </html>

v...

User  
0 rated :

hey Ethan,

I've tried that and something a little similar, but the only issue that I've seen with it, is that if you load() this cloned playlist, or any other playlist for that matter, it resets what's playing in favor of the subsequent loaded playlist. that's the behavior I'm trying to avoid.

it doesn't really make sense to have to completely clean slate anytime you want to change the active playlist. i'd much rather only have to use load() _once_ and toy around with that initially loaded playlist, not load a new one and wipe out what's currently playing.

seems like the way it is currently defeats the purpose of having a playlist/queue.

Ethan Feldman

JW Player Support Agent  
0 rated :

Yeah, it is not possible to do that, I’m afraid. It will always stop the player.

v...

User  
0 rated :

this might be a not possible also, but it doesn't hurt to ask:

let's say if I instead pass my own implementation of a playlist/queue, let's say a variable:

jwplayer('selector').setup({ playlist: coolPlaylist });

as it stands, the playlist option is immutable. is it possible to send some sort of event to jwplayer that says "re-read the value of coolPlaylist?" therefore it can become mutable?

or at the very least, would your colleagues or yourself be able to point me to the part of the codebase where that playlist value gets set in stone, and perhaps I could do my own research and find a hacky means of accomplishing this?

thanks again for your time.

Ethan Feldman

JW Player Support Agent  
-1 rated :

You could possibly do that, but not sure what part of the source has that, sorry.

This question has received the maximum number of answers.