Wednesday 1 August 2007

Interacting Silverlight (1.0) and ActiveX Media Player

Here is the Html



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<!-- saved from url=(0014)about:internet -->
<head>
<title>Silverlight Project Test Page </title>

<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript" src="TestPage.html.js"></script>
<style type="text/css">
.silverlightHost { width: 640px; height: 480px; }
</style>
<SCRIPT LANGUAGE="JavaScript">
// Browser sniff -- the following code does a very simple browser check and rates the
// browser as either Internet Explorer on a Win32 platform or not, so that we
// know to use the ActiveX model, or the plug-in Model.
var sBrowser = navigator.userAgent;
if ((sBrowser.indexOf("IE") > -1) && (navigator.platform == "Win32"))
{
sBrowser = "IE";
} else {
sBrowser = "nonIE";
}
// end browser sniff

function showClick() // This function is called by the btnShowControls button.
// It sets the ShowControls property of Media Player to true.
{
if (sBrowser == "IE") {
document.MediaPlayer1.ShowControls = true;
} else {
document.MediaPlayer1.SetShowControls(true);
}
}

function hideClick() // This function is called by the btnHideControls button.
// It sets the ShowControls property of Media Player to false.

{
if (sBrowser == "IE") {
document.MediaPlayer1.ShowControls = false;
} else {
document.MediaPlayer1.SetShowControls(false);
}
}

function muteClick() // This function is called by the "Mute" button.
// It toggles the state of the Mute property of the Media Player.
{
var bMuteState;

if (sBrowser == "IE") {
bMuteState = document.MediaPlayer1.Mute;
} else {
bMuteState = document.MediaPlayer1.GetMute();
}

if (bMuteState == true) {
document.myButtons.btnMute.value="Mute";
if (sBrowser == "IE") {
document.MediaPlayer1.Mute = false;
} else {
document.MediaPlayer1.SetMute(false);
}
} else {
document.myButtons.btnMute.value="Un-Mute";
if (sBrowser == "IE") {
document.MediaPlayer1.Mute = true;
} else {
document.MediaPlayer1.SetMute(true);
}
}
}

</SCRIPT>
</head>

<body>
<!-- BEGIN GENERIC ALL BROWSER FRIENDLY HTML FOR WINDOWS MEDIA PLAYER -->
<OBJECT ID="MediaPlayer1" width=160 height=112
classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
standby="Loading Microsoft Windows Media Player components..."
type="application/x-oleobject">
<PARAM NAME="FileName" VALUE="mms://wm.microsoft.com/ms/sbnasfs/wmt/turtle28.asf">
<PARAM NAME="ShowControls" VALUE="0">
<EMBED type="application/x-mplayer2"
pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/"
SRC="mms://wm.microsoft.com/ms/sbnasfs/wmt/turtle28.asf"
name="MediaPlayer1"
width=160
height=112
ShowControls=0></EMBED>
</OBJECT>
<!-- END GENERIC ALL BROWSER FRIENDLY HTML FOR WINDOWS MEDIA PLAYER -->
<div id="SilverlightControlHost" class="silverlightHost" >
<script type="text/javascript">
createSilverlight();
</script>
</div>
</body>
</html>


Here is the XAML




<Canvas x:Name="parentCanvas"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<TextBlock Text="click me" FontSize="50" MouseLeftButtonDown="showClick" Canvas.Top="50"/>

</Canvas>

No comments: