We help IT Professionals succeed at work.

Pass QueryString Value to Silverlight javascript file

Hi
I just downloaded the trial version of Expression encoder and built a silverlight video player,
Question is how can i change which video to play based on a querystring value.

In the javascript code snippet below, i want to change: mediaUrl": "WinVideo-HDI-VS08-AJAX-Support.wmv  to a variable called: vidToPlay which would have the name of the video to play attached to a querystring ?vidToPlay=WinVideo-HDI-VS08-AJAX-Support.wmv.

Any help would be appreciated
George

--------------------------------------------------

function get_mediainfo(mediainfoIndex) {
    switch (mediainfoIndex) {        

        case 0:
            return  { "mediaUrl": "WinVideo-HDI-VS08-AJAX-Support.wmv",
                      "placeholderImage": "",
                      "chapters": [              
                                  ] };                                                                
                         
        default:
             throw Error.invalidOperation("No such mediainfo");
     }
}
Comment
Watch Question

b0lsc0ttIT Manager
CERTIFIED EXPERT

Commented:
If I understand you correctly you want ...

var vid2play = document.location.href.toString().match(/?vidToPlay=(.+)$/)[1];

... and then ...

function get_mediainfo(mediainfoIndex) {
    switch (mediainfoIndex) {        

        case 0:
            return  { "mediaUrl": vid2play,
                      "placeholderImage": "",
                      "chapters": [              
                                  ] };                                                                
                         
        default:
             throw Error.invalidOperation("No such mediainfo");
     }
}

This assumes that is all you have in the URL.  Also I assume you just want to change the file name and the "mediaUrl" part is important as it is.

Let me know how this works or if you have a question.

bol
Systems architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
Check this:
var vidToPlay="WinVideo-HDI-VS08-AJAX-Support.wmv";
if(location.search){
  var _par = location.search.split(/vidToPlay\=/i);
  if(_par.length>1){
    vidToPlay=unescape((_par[1]+"&").split("&")[0]);
  }
}
 
function get_mediainfo(mediainfoIndex) {
    switch (mediainfoIndex) {        
 
        case 0:
            return  { "mediaUrl": vidToPlay,
                      "placeholderImage": "",
                      "chapters": [               
                                  ] };                                                                
                          
        default:
             throw Error.invalidOperation("No such mediainfo");
     }
} 

Open in new window

Author

Commented:
Hi
Sorry for delay, never got email from EE saying reply had been posted.

Below is what i currently have:

-------------------------------------Index.aspx page
public string vidToPlay;
protected void Page_Load(object sender, EventArgs e)
        {
        vidToPlay = Request.QueryString["VidID"].ToString();
       }

----------------------- JS Class------------------------------

function get_mediainfo(mediainfoIndex) {
    switch (mediainfoIndex) {        

        case 0:
            return  { "mediaUrl": "WinVideo-HDI-VS08-AJAX-Support.wmv",
                      "placeholderImage": "",
                      "chapters": [              
                                  ] };                                                                
                         
        default:
             throw Error.invalidOperation("No such mediainfo");
     }
}

------------------------
So I need to pass: WinVideo-HDI-VS08-AJAX-Support.wmv which would be the value vidToPlay to the JS class and insert the value here:   return  { "mediaUrl": "WinVideo-HDI-VS08-AJAX-Support.wmv",

Hope this explains things more clearly
George

Author

Commented:
I'm a novice at javascript, but once i relized i could put the var VidToPlay in my aspx page then create a variable that i could insert into code i then understood how it works.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.