Synchronous (yes, wihout 'a') playlist loading (Projekktor Core)

by Stoyicker @, Wednesday, August 08, 2012, 20:25 (314 days ago)
edited by Stoyicker, Wednesday, August 08, 2012, 20:57

Hi,

I'm almost finished with my project. Basically, it consists of a projekktor object, which plays a JSON playlist loaded from a XML file. When it finishes, it runs a php file which modifies the XML file, and then refetches the XML file (with the intention of getting a brand new playlist. However, this is not what happens. Take a look at the important code:

player.addListener('done', updatePlaylist);
function updatePlaylist() {
				$.post('updatePlaylist.php', function () {}).error(function () {
                    alert('Error when trying to run update.php');
                });
                player.setFile(loadJsonPlaylist(), 'text/json');
                player.setPlay(true);
            }

HOWEVER, in the next triggering of the 'done' event, the new playlist is loaded properly. But why? What I guess is happening is that the .setFile method doesn't block itself until finished so the player starts to load the playlist but in the mean time, because of the setPlay(true) call, it repeats the old playlist. Somewhere in the meantime of that playing, the setFile method finishes and, when the repeated playlist finishes, the just loaded one is played.

My questions: Am I right? And, if so, how can I make some kind of add/fix that makes the setFile behave as blocking or solve my problem?

EDIT: Please, do not suggest something like

player.setFile(loadJsonPlaylist(), 'text/json')}, 1000);


It's not a valid solution right now. The proper solution would be kind of an event when the $post is finished.

  552 views

Complete thread:

 RSS Feed of thread