1

I have a javascript question. I'm trying to dynamically build a plugins string variable (optPlugins) and insert into a setup for jwplayer but it doesn't work. For example:

This does not work:

function jsCreatePlayer(sStartVid)
{
var optPlugins = '{ "dplaylists-1": { "dxmlpaths": "/jw/playlist_latest.xml", "dposition": "top", "dskin": "/jw/DPlaylistsSample.swf", "dtarget": "_self" } }';

jwplayer('mainplayer').setup({
'flashplayer': '/jw/player.swf',
'file': sStartVid,
'plugins': optPlugins,
'autostart': 'true',
'width': '577',
'height': '324'
});
}

This does:

function jsCreatePlayer(sStartVid)
{
jwplayer('mainplayer').setup({
'flashplayer': '/jw/player.swf',
'file': sStartVid,
'plugins': { "dplaylists-1": { "dxmlpaths": "/jw/playlist_latest.xml", "dposition": "top", "dskin": "/jw/DPlaylistsSample.swf", "dtarget": "_self" } },
'autostart': 'true',
'width': '577',
'height': '324'
});
}

Note the only different between the two is I copy the optPlugins var right into the plugins:. I'm not good with this, are these JSON options or something? How would I get jwplayer's .setup to properly eval(?) optPlugins? Its not a jwplayer problem, I could just as easily have this question for jquery options too I think.

Thanks.

1
  • 1
    The actual difference is that your variable optPlugins is a String, whereas in the other it's an object. If you remove the single quotes around optPlugins it should work exactly the same. Commented Apr 4, 2012 at 3:23

1 Answer 1

2

use like following code,

var optPlugins = { "dplaylists-1": { "dxmlpaths": "/jw/playlist_latest.xml", "dposition": "top", "dskin": "/jw/DPlaylistsSample.swf", "dtarget": "_self" } };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.