/    Sign up×
Community /Pin to ProfileBookmark

Advanced Function calls – please help

Hi There,

I wonder if anyone would be so kind as to help me with javascript code that i cannot seem to understand. I’m trying to write a media player that works cross browser and cross platform. I’m trying to embed windows media player and effectively creating my own skin.

[URL=”http://www.hydrate.org.uk/soundlab/”]http://www.hydrate.org.uk/soundlab/[/URL] is the url of the website.
Origionaly I was checking the browser and platform on the player.php which was invoked by the index.php – Now i’m trying to do the tests before player.php opens via Launch_Player.js

player_open(file_to_open) // This function invokes 2 functions which retrieve
the browser and platform (Get_Browser_Platform(vpass); + _Get_Info(vpass, file_to_open)?

The intended outcome is to retrieve the relevant code for the player then open a new window and print the HTML for player.php

the js file is embedded within the <head> tags as follows (4 js files are also present)

[QUOTE]

<script language=”JavaScript” src=”javascript/Launch_Player.js” ></script>

[/QUOTE]

and the code that invokes the function is (echo’d by php)

[QUOTE]

echo “<a href=”index.php?addtrack=audio/” . $file . “” style=’cursor:pointer;’ onclick=”javascript:player_open(“audio/” . $file . “”); return false” onmouseover=’javascript : starttimer2(“$n”)’ onmouseout=’javascript : stoptimer2(“$n”)’><h5 id=’tune$n’ class=’tune’>$track_full_name</h5></a>”;

[/QUOTE]

Please go easy on me as I’m new to javascript (newbie)
Thanks for any help in advance

—– Launch_Player.js ———

[CODE]
// JavaScript Document

function _Get_Info(x,track)
{
switch (x)
{
case 0:
break;

case 1:
break;

case 4:

break;
}

switch (_platform)
{
case 3:
// functions to place player html into Player and return to player_open
break;
}
return Player;
}

function Get_Browser_Platform(x)
{
if (-1 != navigator.userAgent.indexOf(‘MSIE’))
{
if (-1 != navigator.userAgent.indexOf(‘MSIE 8’))
{x = 0;}
else if (-1 != navigator.userAgent.indexOf(‘MSIE 7’))
{x = 7;}
else if (-1 != navigator.userAgent.indexOf(‘MSIE 6’))
{x = 8;}
else
{x = 9;}
}
else if (-1 != navigator.userAgent.indexOf(‘Firefox’))
{x = 1;}
else if (-1 != navigator.userAgent.indexOf(‘Chrome’))
{x = 2;}
else if (-1 != navigator.userAgent.indexOf(‘Opera’))
{x = 3;}
else if (-1 != navigator.userAgent.indexOf(‘Safari’))
{x = 4;}
else if (-1 != navigator.userAgent.indexOf(‘Konqueror’))
{x = 5;}
else if (-1 != navigator.userAgent.indexOf(‘Epiphany’))
{x = 6;}
return x;
}

function player_open(file_to_open)
{
var vpass;
Get_Browser_Platform(vpass) return true;
_Get_Info(vpass, file_to_open) return true;

PlayerWin = window.open(”,’_blank’,’width=202,height=302,top=0,left=0,screenX=0,screenY=0,resizable=1,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0′);

PlayerWin.document.writeln(‘<?php’);
PlayerWin.document.writeln(‘session_start();’);
PlayerWin.document.writeln(‘?>’);
PlayerWin.document.writeln(‘<html>’);
PlayerWin.document.writeln(‘<head>’);
PlayerWin.document.writeln(‘<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />’);
PlayerWin.document.writeln(‘<title>Sound Lab Media Player</title>’);
PlayerWin.document.writeln(‘<link href=”css/style.css” rel=”stylesheet” type=”text/css” />’);
PlayerWin.document.writeln(‘<link href=”css/slider.css” rel=”stylesheet” type=”text/css” />’);
PlayerWin.document.writeln(‘<script language=”JavaScript” src=”javascript/slider.js” ></script>’);
PlayerWin.document.writeln(‘<script language=”JavaScript” src=”javascript/player.js” ></script>’);
PlayerWin.document.writeln(‘<script language=”JavaScript” src=”javascript/user_detail.js” ></script>’);
PlayerWin.document.writeln(‘<script type=”text/javascript”>’);
PlayerWin.document.writeln(‘var Tunes = new Array();’);
PlayerWin.document.writeln(‘var platform = 0;’);
PlayerWin.document.writeln(‘var browser = 0;’);
PlayerWin.document.writeln(‘var _Playlist;’);
PlayerWin.document.writeln(‘var media;’);
PlayerWin.document.writeln(‘var x;’);
PlayerWin.document.writeln(‘var y;’);
PlayerWin.document.writeln(‘var start_track = “‘ + file_to_open + ‘”;’);
PlayerWin.document.writeln(‘<?php’);
PlayerWin.document.writeln(‘echo “var total = new Number(“. $_SESSION[‘track_count’] .”);nn”;’);
PlayerWin.document.writeln(‘?>’);
PlayerWin.document.writeln(‘function Load_Player(){‘);
PlayerWin.document.writeln(‘x = document.getElementById(‘Media_Player’));’);
PlayerWin.document.writeln(‘_pre_Load(x);’);
PlayerWin.document.writeln(‘var n = 0; ‘);
PlayerWin.document.writeln(‘while (n < total){‘);
PlayerWin.document.writeln(‘<?php’);
PlayerWin.document.writeln(‘$n = $_SESSION[‘track_count’];’);
PlayerWin.document.writeln(‘for($i=0;$i<$n;$i++){‘);
PlayerWin.document.writeln(‘echo “media = x.newMedia(‘” . $_SESSION[‘track’.$i] . “‘);n”;’);
PlayerWin.document.writeln(‘echo “Tunes[” . $i . “] = ‘” . $_SESSION[‘track’.$i] . “‘;n”;’);
PlayerWin.document.writeln(‘echo “x.currentPlaylist.appendItem(media);”;}’);
PlayerWin.document.writeln(‘?>’);
PlayerWin.document.writeln(‘n++;}’);
PlayerWin.document.writeln(‘y = x.currentPlaylist.count;’);
PlayerWin.document.writeln(‘document.getElementById(‘Track_len’).innerHTML = y;’);
PlayerWin.document.writeln(‘</script>’);
PlayerWin.document.writeln(‘</head>’);
PlayerWin.document.writeln(‘<body onLoad=”_Get_Browser(start_track); _Get_OS(); _Get_Info(); Load_Player();”>’);
PlayerWin.document.writeln(‘<div style=”position:absolute; width:200px; height:300px; left:0px; top:0px; border:solid thin #FFFFFF;”>’);
PlayerWin.document.writeln(‘<p id=”Display” style=”font-size:10px;”></p>’);
PlayerWin.document.writeln(‘<p id=”Slider_val” style=”font-size:10px;”></p>’);
PlayerWin.document.writeln(‘<p id=”Track_len” style=”font-size:10px;”></p>’);
PlayerWin.document.writeln(‘<p id=”On_Off” style=”font-size:10px;”></p> <br />’);
PlayerWin.document.writeln(‘<p id=”browser_P” style=”font-size:10px;”>Browser</p><br /> ‘);
PlayerWin.document.writeln(‘<p id=”platform_P” style=”font-size:10px;”>Platform</p>’);
PlayerWin.document.writeln(‘<input class=”textbox” type=”button” onClick=”Initialize()” value=”Play”>’);
PlayerWin.document.writeln(‘<input class=”textbox” type=”button” onClick=”stop_player()” value=”Stop”>’);
PlayerWin.document.writeln(‘<input class=”textbox” type=”button” onClick=”VolumeUp()” value=”+”>’);
PlayerWin.document.writeln(‘<input class=”textbox” type=”button” onClick=”VolumeDown()” value=”-“>’);
PlayerWin.document.writeln(‘<input class=”textbox” type=”button” onClick=”Rewind()” value=”<<“>’);
PlayerWin.document.writeln(‘<input class=”textbox” type=”button” onClick=”FastForward()” value=”>>”>’);
PlayerWin.document.writeln(‘<input class=”textbox” type=”button” onClick=”javascript:PlayerObj.controls.next();” value=”Next”>’);
PlayerWin.document.writeln(‘<input class=”textbox” type=”button” onClick=”javascript:PlayerObj.controls.previous();” value=”Previous”>’);
PlayerWin.document.writeln(‘<div class=”horizontal_track” id=”horizontal_track_1″ >’);
PlayerWin.document.writeln(‘<div class=”horizontal_slit” id=”horizontal_slit_1″ >&nbsp;</div>’);
PlayerWin.document.writeln(‘<div class=”horizontal_slider” id=”horizontal_slider_1″ style=”left: 0px;”‘);

PlayerWin.document.writeln(‘onmousedown=”stop_adjust(); slide(event, ‘horizontal’, 100, 0, 100, 101, 0, ‘value_display_1’);” >&nbsp;</div></div> ‘);
PlayerWin.document.writeln(‘<div class=”display_holder” >’);
PlayerWin.document.writeln(‘<input id=”value_display_1″ class=”value_display” type=”text”
value=”0″ onFocus=”blur(this);” /></div>’);
PlayerWin.document.writeln(‘</div>’);
PlayerWin.document.writeln(‘<div id=”Player_Holder” style=”display:none”>’);
PlayerWin.document.writeln(vpass);
PlayerWin.document.writeln(‘</div></body></html>’);
PlayerWin.focus();
PlayerWin.document.close();
}
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mavigozlerAug 22.2009 — 
  • 1. The first problem I can see is that in getting JS to write to your opened player window, you are writing in PHP script. Since this is being done on the client side, how do suppose the client is going to interpret PHP, which is on the server side? In solving this, you may want an AJAX solution, or you probably should find a way to get the PHP-side done on the server side and leave the JS on the client side.


  • 2. When script the HTML to your player window, use techniques to validate the HTML within your popup window. A lot of problems are solved in this way. If I were you, validate in Strict HTML and nothing else (not loose/transitional/frameset/whatever...it's all deprecated). I notice you don't have a DOCTYPE declaration--yes, it's essential---and you make use of deprecated attributes in some tags. Moreover, in Javascript used within HTML documents, always escape forward slashes in etagos especially! That is,

    not [FONT="Courier New"][COLOR="SeaGreen"][B]document.write("</script>");[/B][/COLOR][/FONT]

    but instead [FONT="Courier New"][COLOR="SeaGreen"][B]document.write("</script>");[/B][/COLOR][/FONT]


  • It prevents the HTML parser from getting excited about text it should not be interpreting.

  • 3. I am of the opinion that checking for browsers is fully a waste of time. If you're worried about the host or built-in object hierarchy of a browser, test the existence of the object rather than looking for browsers, since FF is notorious for trying to pass itself off as IE to servers. Don't ask if it's "IE" if you want to exploit ActiveXObject...instead:

    if (ActiveXObject) { // or typeof(ActiveXObject) != "undefined"

    // then use my ActiveXObject code

    } else if (netscape) {

    // then use the Mozilla/Firefox code

    }
  • Copy linkTweet thisAlerts:
    @Russ_BoothauthorAug 22.2009 — Hi

    Am I right in thinking that the Active X object is similar if not the same to the WMP Object - Can I still access Player.controls .play() etc

    Thanks again for your help you have been a big help - I spend hours some times days trying to debug code that i can't seem to find a problem with

    Cheers Russ

    Can I add that origionally the JS Script was on player.php which was opened by

    [CODE]
    PlayerWin = window.open('player.php',1,'width=202,height=302,top=0,left=0,screenX=0,screenY=0,resizable=1,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0');[/CODE]


    I kept finding that functions were undefined (probably for reasons you just mentioned)

    Thanks
    ×

    Success!

    Help @Russ_Booth 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 6.16,
    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: @nearjob,
    tipped: article
    amount: 1000 SATS,

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

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...