Reputation: 325
I have the following Javascript for playing music files as playlist using jwplayer
function playAllAudio() {
var audioDiv = "<div id='audioplayer'></div>";
//Get ids from selected files
var sData = $('input', oTable.fnGetNodes()).serialize();
$.post("mediaStream.do", {OID : sData},function(data) {
jwplayer('audioplayer').setup({
'controlbar': 'bottom',
'width': '470',
'height': '24',
//'playlist': [{file:'mp3:audio/audioMotion'},{file:'mp3:audio/audioTangled'},{file:'mp3:audio/audioSunHands'}],
'playlist': data,
'provider': 'rtmp',
'streamer': 'rtmp://XXXXXXX.cloudfront.net:1935/cfx/st',
'modes': [
{type: 'flash', src: 'https://YYYYYYYYY.cloudfront.net/player.swf'}
]
});
});
}
with data being created dynamically as a JSON string, where the values are song filenames formatted for jwplayer
var data = "[{file:'mp3:audio/audioMotion'},{file:'mp3:audio/audioTangled'}]";
How ever, when i use the variable the 'data', the jwplayer does not work. How do i make it work with data passed from server to the javascript?
Upvotes: 1
Views: 1111
Reputation: 6228
The data being created dynamically is a JSON string, but the jwplayer's playlist
config should be an array, you must cover the string to an array first:
var data = "[{file:'mp3:audio/audioMotion'},{file:'mp3:audio/audioTangled'}]";
data = JSON.parse(data); // with out IE8-
but JSON
is not support in IE8-, you can use Douglas Crockford's json2 to fixed it.
Upvotes: 3
Reputation: 8027
You can pass it in just like you are doing so, as a response from the mediaStream.do call.
Are you sure the json is valid? Have you tried validating the response with http://jsonlint.com/?
Upvotes: 0