...

View Full Version : HELP: Embedded media player URL Param and Javascript



MadLogic
11-07-2006, 10:06 PM
I have embedded media player to a page.
The player is supposed to get the url for the file to play from a javascript that collects user choice from a form.

The form is on one page, the javascript lies in an external .js file & the player is on another page that is called from within the javascript.

What I cant figure out is how to pass the URL value to the media player from the javascript.
Here's my script:

function LocateMovie() {
var loc = "video/";
var add = document.form.promo.value;
var con = document.form.speed.value;
var url = loc + add + con + '.wmv'
parseFloat(url);
if (add == '') {
alert("Please Select a sample video to view");
} else if (con == '') {
alert("Please select your connection speed");
} else {
location.href = "player.html";
}
}

And voila, the notorious media player object where the 'url' variable should be inserted to fill in the value for the URL parameter:

<Object etc..
<param name="URL" value="??">
* value in the above tag is equal to 'url' variable defined in the script.
</object etc...

Any Ideas? Other than using 12 different html pages of course...

Regards

brandonH
11-07-2006, 10:46 PM
try usign the full path name of the file, not just the short path name.

if the page that you have i suppose in an iframe is not in the same directory as the main page, you cannot call to the file the same as if you call to it from the main page, cuz the directories are different.

brandonH
11-07-2006, 10:49 PM
hang on, you are using one page that opens up another window (the media player) ? and you wnat to know how to pass the url from the parent page to the media player page? is that right?

brandonH
11-07-2006, 11:01 PM
function LocateMovie() {
var loc = "video/";
var add = document.form.promo.value;
var con = document.form.speed.value;
var url = loc + add + con + '.wmv'
parseFloat(url);
if (add == '') {
alert("Please Select a sample video to view");
} else if (con == '') {
alert("Please select your connection speed");
} else {
var ObjecT="<object><param name='URL' value='"+url+"'>"
var MediaWin=window.open("","mywin","height=300,widht=300");
var content="<html><head><title>Media Player</title></head>";
content+="<body><div id=div1></div>";
content+="</body></html>"
MediaWin.document.getElementById('div1').innerHTML=ObjecT;

}
}

MadLogic
11-08-2006, 06:55 AM
Yes, what am trying to do is pass the url variable to the media player.
Your solution is with no doubt a good way to go, but the thing is that my media player is within a full html page...
So my command must target the media player object... or if there's a way to make the player object retrieve that variable by itself. For I have a parseFloat(url...) that should push the variable outside the script itself and make it accessible by other functions.
By the way I am no javascripting genie...

Regards

MadLogic
11-08-2006, 07:06 AM
By the way, I tried your solution, and got an "document.getElementById(...)' is null or not an object.

Regards

brandonH
11-08-2006, 02:33 PM
well im not familiar with <object> tag. I use the <embed> tag to do things such as this.

<embed src="path/to/file/file.wmv">



<script type=text/javascript>
var MediaWin
function ChngEmb(url){
MediaWin=window.open('','mywin',"width=400,height=400,toolbars=no,status=no");
if(MediaWin.document.getElementById('div1')){
MediaWin.document.getElementById('div1').innerHTML="<embed src='"+url+"' id=embedObj>";
MediaWin.focus();
}else{
var contents="<html><head><title>Media Player</title></head><body>";
contents+="<div id=div1><embed src='"+url+"' id=embedObj></div></body></html>"
MediaWin.document.write(contents);
}
}
</script>


<input type=button value='play 1' onclick="ChngEmb('path/to/file/file.wmv');">
<input type=button value='play 2' onclick="ChngEmb('path/to/file/file2.wmv');">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum