/    Sign up×
Community /Pin to ProfileBookmark

Choose video file to play based on OS/Platform?

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

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJun 06.2003 — I have not tested the code below,but I don't seewhy it won't run..try it out..

<i>
</i>&lt;script type="text/javascript"&gt;
&lt;!--
var OS = navigator.platform;
function Process(){
var obj = document.getElementById("div_1");
var filePath = "";
if(OS.indexOf("Win")&gt;-1){//play wind media player
"../videos/adrienne.wmv"
}else{//play quick time
filePath = "../videos/adrienne.mov";
}
obj.innerHTML = '&lt;embed src="'+filePath+'" autostart="True" loop="False"&gt;'
}
//--&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="Process();"&gt;
&lt;div id="div_1" class="table-with-thin-border"&gt;
&lt;/div&gt;
Copy linkTweet thisAlerts:
@adinanetauthorJun 06.2003 — 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
  • Copy linkTweet thisAlerts:
    @adinanetauthorJun 06.2003 — 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
  • Copy linkTweet thisAlerts:
    @Khalid_AliJun 06.2003 — 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
    Copy linkTweet thisAlerts:
    @adinanetauthorJun 06.2003 — 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

    ? ? ?
    Copy linkTweet thisAlerts:
    @Khalid_AliJun 06.2003 — ?

    You are welcome...
    ×

    Success!

    Help @adinanet spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...