﻿//<!--
// ---------------------------------------------------------------------
// Compatible with StreamSync Encoder 1.4.15+. 2004-03-17.
// Please notice. This code is provided only as an example of how to
// layout and program a video player for use with StreamSync.
// ---------------------------------------------------------------------

var mElementID = "";
var mMimeType = "";
var mPayload = "";
var mCurrentSrc = "";

var mVideoSource = "";
var mMediaPath = "";

var is_wm = false;
var is_real = false;
var is_qt = false;

var uAgent = navigator.userAgent.toLowerCase();

// ---------------------------------------------------------------------
// Init 
//
// This method is called from the SCRIPT.HTM page that is loaded from the
// Media Player URL script command. 
//
// URL is the SCRIPT.HTM document.location value
// ---------------------------------------------------------------------

function Init(URL)
{
//alert(URL);
	UpdateFromParameters(URL);
	UpdatePage(mElementID, mMimeType, mPayload);
}

// ---------------------------------------------------------------------
// GetParameters 
//
// This method extracts the parameters from the provided URL. 
//
// ---------------------------------------------------------------------

function GetParameters(URL)
{
	var StrArray = String(URL).split("?");
	return String(StrArray[1]);
}

// ---------------------------------------------------------------------
// UpdateFromParameters 
//
// This method retreives the parameters from the provided URL. Parameters 
// are separated by the & character. 
//
// ---------------------------------------------------------------------

function UpdateFromParameters(URL)
{
	var parameters =  GetParameters(URL);
	var StrArray = parameters.split("&");
	
	mElementID = String(StrArray[0]);
	mMimeType =  String(StrArray[1]).toLowerCase();
	mPayload =  String(StrArray[2]);	// 2004-02-17 Removed unescape
}

// ---------------------------------------------------------------------
// UpdatePage 
//
// This method updates the page depending on the provided parameters. 
//
// ElementID adresses the specific element on the page to update.
// MimeType is the elements media type.
// Payload is the actual payload.
//
// Syntax for the parameters string: ElementID&MimeType&Payload
// 
// ---------------------------------------------------------------------

function UpdatePage(ElementID, MimeType, Payload)
{
	if(ElementID == "undefined") return;
	if(MimeType == "undefined") return;
	if(Payload == "undefined") return;

//    alert("Element:" + ElementID + "  MimeType:" + MimeType + "  Payload:" + Payload);

	if(MimeType.indexOf("image/") > -1){
		SetImage(ElementID, Payload);
	}
	else if(MimeType.indexOf("text/") > -1){
		SetText(ElementID, Payload);
	}
	else{
		//Ignore this MIME type
	}
	
}

// ---------------------------------------------------------------------
// SetImage 
//
// This method updates an image on the page. 
//
// ElementID adresses the specific element on the page to update.
// Payload is the actual payload.
//
// ---------------------------------------------------------------------

function SetImage(ElementID, Payload)
{
	if (Payload.indexOf("http://") == -1)
	{
		Payload = mMediaPath + Payload;
	}
	
	if(mCurrentSrc == Payload + "/" + ElementID) return;
	mCurrentSrc = Payload + "/" + ElementID;

	eval("parent.document.getElementById('" + ElementID + "').src = 'ppimages/' + \"" + Payload + "?" + new String(Math.round(Math.random() * 1000)) + "\"");
}

// ---------------------------------------------------------------------
// SetText 
//
// This method updates a text field on the page. 
//
// ElementID adresses the specific element on the page to update.
// Payload is the actual payload.
//
// ---------------------------------------------------------------------

function SetText(ElementID, Payload)
{	
	// Replace %A with line break
	var re = /%0A/g;
	Payload = unescape(Payload.replace(re, "<br>"));	
	
	var nav4Layer = eval("document." + ElementID);				// Adress your text element for Navigator 4.5 here
	
	if(nav4Layer != null){
		// Use Netscape layers to update the text 
		nav4Layer.document.write("<font class=\"Style1\"><center>" + Payload + "</center></font>");
		nav4Layer.document.close();
	}
	else{
		var docElement = document.getElementById(ElementID);	// Adress your text element for other compliant browsers here
		if(docElement != null){
			// Use innerHTML to update the text (not a W3C standard, but it works for IE and NS6.2)
			if(docElement.innerHTML != Payload) docElement.innerHTML = Payload;

			UpdateText(docElement);
		}
	}
}

// ---------------------------------------------------------------------
// HandleCommandScript 
//
// The provided CommandScript describes the multimedia element to
// display in the browser.
//
// Syntax for the ScriptComand string: #ElementID#MimeType#Payload
//
// Windows + IE only!
//
// ---------------------------------------------------------------------

function HandleCommandScript(ScriptType, CommandScript) 
{
	
	if(ScriptType == "URL") return;

	// Parse the ScriptCommand string
	ParseCommandScript(CommandScript);
		
	// Update the element on the web page 
	UpdatePage(mElementID, mMimeType, mPayload);
}

// ---------------------------------------------------------------------
// ParseCommandScript 
//
// Updates the webpage according to the provided layout element object. 
//
// LayoutElement is a description of the multimedia element.
// ---------------------------------------------------------------------

function ParseCommandScript(ScriptCommand){

	var Attributes = ScriptCommand.split("#");
	if(Attributes == null) return; // No attributes found
	mElementID = String(Attributes[1]);
	mMimeType =  String(Attributes[2]).toLowerCase();
	mPayload =  String(Attributes[3]);
}

// ---------------------------------------------------------------------
// Detect from the provided VideoSource which player to use
// ---------------------------------------------------------------------

function DetectPlayerType(VideoSource)
{
	// Extract the extension from the extracted media path
	var Extension = GetExtension(VideoSource);
		
	// Extract the right type of player from the extracted extension
	if(".ram;.rm;".indexOf(Extension) > -1){
		is_real = true;
	}
	else if(".asx;.wmv;asf;avi;".indexOf(Extension) > -1){
		is_wm = true;
	}
	else if(".mov;mpg;mpeg;".indexOf(Extension) > -1){
		is_qt = true;
	}
}

// ---------------------------------------------------------------------
// Extract extension from the provided MediaPath
// ---------------------------------------------------------------------

function GetExtension(MediaPath)
{
	var nLastDot = MediaPath.lastIndexOf(".");
	if(nLastDot != -1){
		var Extension = MediaPath.substring(nLastDot+1, MediaPath.length);
		return (Extension);
	}
}

// ---------------------------------------------------------------------
// Extract parameters from the document.location variable
// ---------------------------------------------------------------------

function ParseURL(URL)
{
	var StrArray = String(URL).split("?");
	var StrArray2 = String(StrArray[1]).split("&");
	
	mVideoSource = unescape(StrArray2[0]);
	mMediaPath = unescape(StrArray2[1]);
	
	//alert("mVideoSource = " + mVideoSource);
	//alert("mMediaPath = " + mMediaPath);
}

// ---------------------------------------------------------------------
// Returns the videosource to open by the player
// ---------------------------------------------------------------------

function GetVideoSource()
{
	return mVideoSource;
}

// ---------------------------------------------------------------------
// Invoke the player that fit the provided URL
// ---------------------------------------------------------------------

function WritePlayer(URL)
{
	ParseURL(URL);
	DetectPlayerType(GetVideoSource());
	
	if(is_real){
		// Write out the Real Player
		WriteRealPlayer(GetVideoSource());
	}
	else if(is_wm){
		// Write out the Windows Media Player
		WriteWindowsMediaPlayer(GetVideoSource());
	}
	else if(is_qt){
		// Write out the Quick Time Player
		WriteQuicktimePlayer(GetVideoSource());
	}
}

// ---------------------------------------------------------------------
// Methods for writing out embeded players
// ---------------------------------------------------------------------

function WriteWindowsMediaPlayer(VideoSource) 
{
	is_wm = true;
	
	width = 240;
    height = 180;
        
	var ObjectTag = "<OBJECT ID=\"MediaPlayer\" name=\"MediaPlayer\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\" CLASSID=\"CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95\" CODEBASE=\"http://www.microsoft.com/ntserver/netshow/download/en/nsmp2inf.cab#Version=5,1,51,415\" standby=\"Loading Microsoft Media Player components...\" type=\"application/x-oleobject\">";
	ObjectTag += "<PARAM NAME=\"AutoStart\" VALUE=\"1\">";
	ObjectTag += "<PARAM NAME=\"FileName\" VALUE=\"" + VideoSource + "\">";
	ObjectTag += "<PARAM NAME=\"ShowControls\" VALUE=\"0\">";
	ObjectTag += "<PARAM NAME=\"ShowStatusBar\" VALUE=\"0\">";
	ObjectTag += "<PARAM NAME=\"AutoSize\" VALUE=\"0\">";
	ObjectTag += "<PARAM NAME=\"ControlType\" VALUE=\"0\">";
	ObjectTag += "<PARAM NAME=\"ShowTracker\" VALUE=\"0\">";
	ObjectTag += "<PARAM NAME=\"InvokeURLs\" VALUE=\"1\">";
	ObjectTag += "<PARAM NAME=\"Volume\" VALUE=\"-100\">";
	ObjectTag += "<EMBED Type=\"video/x-ms-asf-plugin\" pluginspage=\"http://www.microsoft.com/windows/mediaplayer/download/default.asp\" src=\"" + VideoSource + "\" name=\"MediaPlayer\" AutoStart=\"1\" ShowControls=\"0\" ShowStatusBar=\"0\" AutoSize=\"0\" width=\""+width+"\" height=\""+height+"\" DefaultFrame=\"script\" ShowTracker=\"0\" volume=\"-100\">";
	ObjectTag += "</OBJECT>";

	document.write(ObjectTag);
}

function WriteRealPlayer(VideoSource) 
{	
	is_real = true;
	
	width = 320;
	height = 240;
	
	var ObjectTag = "<OBJECT ID=\"MediaPlayer\" CLASSID=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\">";
	ObjectTag +="<PARAM NAME=\"SRC\" VALUE=\"" + VideoSource + "\">";
	ObjectTag +="<PARAM NAME=\"CONTROLS\" VALUE=\"Imagewindow\">";
	ObjectTag +="<PARAM NAME=\"AUTOSTART\" VALUE=\"TRUE\">";
	ObjectTag +="<PARAM NAME=\"NOLABELS\" VALUE=\"TRUE\">";
	ObjectTag +="<PARAM NAME=\"RESET\" VALUE=\"FALSE\">";
	ObjectTag +="<PARAM NAME=\"CONSOLE\" VALUE=\"console1\">";
	ObjectTag +="<PARAM NAME=\"AUTOGOTOURL\" VALUE=\"TRUE\">";
	ObjectTag +="<embed name=\"MediaPlayer\" CONSOLE=\"console1\" type=\"audio/x-pn-realaudio-plugin\" src=\"" + VideoSource + "\" width=\""+width+"\" height=\""+height+"\" controls=\"Imagewindow\" autostart=\"true\" nolabels=\"true\">";
	ObjectTag +="</OBJECT><br>";
	
	document.write(ObjectTag);
}

function WriteQuicktimePlayer(VideoSource)		// Must use player controls. Cannot use custom controls.
{	
	
	is_qt = true;
	
	width = 320;
    height = 240 + 16;
    
	var ObjectTag = "<OBJECT id=\"MediaPlayer\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" height=\"" + height + "\" width=\"" + width + "\" classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\">";
	ObjectTag += "<param name=\"src\" value=\"" + VideoSource + "\">";
	ObjectTag += "<param name=\"CONTROLLER\" value=\"TRUE\">";
	ObjectTag += "<param name=\"SCALE\" value=\"ASPECT\">";
	ObjectTag += "<EMBED NAME=\"MediaPlayer\" SCALE=\"ASPECT\" BORDER=\"0\" CONTROLLER=\"true\" TYPE=\"video/quicktime\" src=\""+VideoSource+"\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\" AUTOPLAY=\"true\" BGCOLOR=\"#FFFFFF\" PLUGINSPAGE=\"http://www.apple.com/quicktime/download/\">";
	ObjectTag += "</OBJECT>";
	
	document.write(ObjectTag);
}	

//--> 