Linear

JSON Playlist - What is wrong? (Projekktor Core)

by Stoyicker @, Monday, August 06, 2012, 22:48 (317 days ago)

Hi,

I'm after using the playlist feature. I've got a playlist in a XML file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<playlist>
<vid src="P_CULTURAL TV.f4v" />
<vid src="P_ANIMACION.f4v" />
</playlist>

It would be very useful for me to directly load the playlist from a XML file instead having to generate a JSON file, which would cause huge changes in my software. However, since the code for 'alternate-playlist.xml' shown at the end of the playlist docs is not published, I'm not able to adapt it (obviously I've already tried loading it directly).

Could anyone tell me how must I structure the XML file so the playlist can be loaded from the file? Or, if it's not possible, tell me why this doesn't work?:

[{"0":{"src":"video\/intro.mp4","type":"video\/mp4"},config: {
				disablePause: true,
		        disallowSkip: true
			}},{"0":{"src":"video\/intro.mp4","type":"video\/mp4"}}]

I've written it as an adaptation of the server.php file.

This is my document.ready:

<script type="text/javascript">
$(document).ready(function() {
    projekktor('#player_a', {
	volume: 1,
	enableFullscreen: true,
	continuous: true,
	playlist: [
		{
			0:{src:'playlist.php', type:'text/json'}
		}
	]
    });
});
</script> 
  796 views

JSON Playlist - What is wrong?

by Stoyicker @, Tuesday, August 07, 2012, 09:41 (316 days ago) @ Stoyicker
edited by Stoyicker, Tuesday, August 07, 2012, 09:57

Okay needed a rest, I just realized the XML file doesn't point to.mp4 files and doesn't have a type attribute. Gonna edit and test.

EDIT: With that edit, it doesn't yet work. However now the 'play' button is displayed, but when pressedit disappears and then reappers (what I guess means that it detects an empty playlist). Here's the XML file now:

<?xml version=1.0" encoding="UTF-8" standalone="no"?>
<playlist>
<vid src="video/intro.mp4" type="video/mp4"/>
<vid src="video/intro.mp4" type="video/mp4"/>
</playlist>
  726 views
Avatar

JSON Playlist - What is wrong?

by sascha ⌂ @, Tuesday, August 07, 2012, 16:28 (316 days ago) @ Stoyicker

Hi Stoyicker,

thanks for your interesting question. It´s a bit funny that the last XML test I did is a couple of month ago.

As I tried to answer your post I figured out that something is going wrong with the XML stuff and I´m currently investigating that. So: Please stay tuned, you have been heard =).

- Sascha

---
Help keeping free Projekktor support alive. Consider to buy supporter license: http://shop.projekktorxl.com/shop/supporter-license/

Tags:
xml, json, playlist

  740 views

JSON Playlist - What is wrong?

by Stoyicker @, Tuesday, August 07, 2012, 17:46 (316 days ago) @ sascha
edited by Stoyicker, Tuesday, August 07, 2012, 20:03

Thanks sascha. Anyway, since I did the post I've been working on a system for parsing the file and creating a JSON object to be used as playlist target, and I'll post it here when it's finished for public usage.

Here it is:

<!DOCTYPE HTML>
<html>
<head>
<title>Aron Multimedia</title>
<link rel="stylesheet" href="theme/style.css" type="text/css" media="screen" />

<script type="text/javascript" src="libs/jquery.min.js"></script>
<script type="text/javascript" src="libs/projekktor.min.js"></script>
<script type="text/javascript" src="libs/xml2json.js"></script>
</head>
<body>

<video id="player_a" class="projekktor fullscreen pphttp" title="Aron Multimedia" width="640" height="360" preload="auto" autoplay></video>

<script type="text/javascript">
$(document).ready(function() {
	player = projekktor('#player_a', {
	volume: 1,
	enableFullscreen: true,
	continuous: true,
	disablePause: true,
	disallowSkip: true,
	playlist: loadJsonPlaylist()
	}
});

function loadJsonPlaylist() 
{
 var xmlDoc;
 var jsonPlaylist;

if (window.XMLHttpRequest){
	xmlDoc = new window.XMLHttpRequest();
	xmlDoc.open("GET", 'playlist.xml', false);
   	xmlDoc.send("");
	jsonPlaylist = xmlToJson(xmlDoc.responseXML);
} else if (ActiveXObject("Microsoft.XMLDOM")){
	xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async = false;
	xmlDoc.load('playlist.xml');
	jsonPlaylist = xmlToJson(xmlDoc);
}
if(window.XMLHttpRequest || ActiveXObject("Microsoft.XMLDOM")){
	var str1 = JSON.stringify(jsonPlaylist);
	var str2 = str1.replace(/{(.*?)\[{"0":{"src"/,'[{"0":{"src"');
	var cut = str2.substring(0,str2.length-2);
	var ret = JSON.parse(cut);
	return ret;
}
alert("Error while loading the playlist.xml file.");
return null;
}

function xmlToJson(xml){
var attr, child, attrs = xml.attributes, children = xml.childNodes, key = xml.nodeType, obj = {}, i = -1, o=0;
if (key == 1 && attrs.length){
	obj[key = o] = {};
	while (attr = attrs.item(++i)){
		obj[key][attr.nodeName] = attr.nodeValue;
	}
	i = -1;
} else if (key == 3){
	obj = xml.nodeValue;
} 
while (child = children.item(++i)){
	key = child.nodeName;
	if (obj.hasOwnProperty(key)){
		if (obj.toString.call(obj[key])!='[object Array]') {
			obj[key] = [obj[key]];
		}
		obj[key].push(xmlToJson(child));
	} else{
		obj[key] = xmlToJson(child);
	}
}
return obj;
}

</script> 


</body>
</html>
  819 views