Click to See Complete Forum and Search --> : Choose video file to play based on OS/Platform?


adinanet
06-06-2003, 08:33 AM
Arggh...I have the concept worked out, I just need help getting the code syntax correct.
I want to create a page where it will sniff out the platform of the user (Mac or PC) and on that criteria choose either a Quicktime (for Mac) or a Windows Media (for PC) video file to play embedded in that page.
What I can't figure out is how to incorporate a Javascript object into an EMBED tag (if that is in fact how to do it). I can guess that the variable would go here: <EMBED src="variable"..., but I'm unsure of the syntax.

Here's the script I have so far...

<SCRIPT language="Javascript" type="text/javascript">
<!--
var bname=navigator.platform;
var vidtype;

if(bname=="MacPPC")
{
vidtype="../videos/adrienne.mov"
}
else
{
vidtype="../videos/adrienne.wmv"
}
//-->
</SCRIPT>

So, now how can I get the EMBED tag to use the variable to play that video. The value is being set, but the video won't load, much less play. This video is not playing in it's own window - it needs to be embedded within an HTML with graphics and text around it.

Thanks in advance for ANY help!!!

-adinanet

Khalid Ali
06-06-2003, 09:27 AM
I have not tested the code below,but I don't seewhy it won't run..try it out..


<script type="text/javascript">
<!--
var OS = navigator.platform;
function Process(){
var obj = document.getElementById("div_1");
var filePath = "";
if(OS.indexOf("Win")>-1){//play wind media player
"../videos/adrienne.wmv"
}else{//play quick time
filePath = "../videos/adrienne.mov";
}
obj.innerHTML = '<embed src="'+filePath+'" autostart="True" loop="False">'
}
//-->
</script>
</head>
<body onload="Process();">
<div id="div_1" class="table-with-thin-border">
</div>

adinanet
06-06-2003, 09:35 AM
Works great for the Quicktime/Mac situation, but for PC I just get a small box with a dot that does nothing...any thoughts (you've been a big help already!)

Any advice on where to learn more about this kind of scripting? I know basic Javascript, but I'd like to be more fluent for these kind of situations!

- Adinanet

adinanet
06-06-2003, 09:41 AM
I'd like to have itbdetect the other way around - so it detects for Mac to use QT first and then for all others it chooses to use Window Media Player?

However, if I flip it this way:

<script type="text/javascript">
<!--
var OS = navigator.platform;
function Process(){
var obj = document.getElementById("div_1");
var filePath = "";
if(OS.indexOf("Mac")>-1){//play quick time
"../videos/adrienne.mov"
}else{//play wind media player
filePath = "../videos/adrienne.wmv";
}
obj.innerHTML = '<embed src="'+filePath+'" autostart="True" loop="False">'
}
//-->
</script>

...it then works for PC, but not for MAC...the script seems to accept the syntax for the "else" situation only...

Any idea what's missing or needs correcting? I really really really appreciate it!!!!

- Adinanet

Khalid Ali
06-06-2003, 09:56 AM
I have a feeling that your OSdetection string is not properly formatted.
do this.

var OS = (navigator.platform).toLowerCase();

and then change the condition from

if(OS.indexOf("Mac")>-1){//play quick time

to

if(OS.indexOf("mac")>-1){//play quick time

adinanet
06-06-2003, 10:24 AM
HALLELUJAH!

Well, I made those changes and also noticed that there was no "filepath =" before the .mov filename in the script, so one or both of those things made a big difference!

So it works cross platform now & I'm doing the happy coding dance. THANK YOU THANK YOU THANK YOU!

-Adinanet
:D :D :D

Khalid Ali
06-06-2003, 10:30 AM
:D
You are welcome...