I am trying to dynamically change the url link of an embeded youtube video from the code-behind on our website.
I am trying to dynamically change the url link of an embeded youtube video from the code-behind on our website.
Here is the HTML code for the video:
<ajax:TabPanel runat="server" ID="Panel5" HeaderText="Videos">
<ContentTemplate>
<table>
<tr>
<td style="width:425px;">
<object width="425" height="344">
<param name="movie" value="http://youtube.com/myvideo/"/>
<param name="allowFullScreen" value="true"/>
<param name="allowscriptaccess" value="always"/>
<embed src="http://youtube.com/myvideo/" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>
</object></td>
</tr>
</table>
</ContentTemplate>
</ajax:TabPanel>
Here is the HTML code for the video:
<ajax:TabPanel runat="server" ID="Panel5" HeaderText="Videos">
<ContentTemplate>
<table>
<tr>
<td style="width:425px;">
<object width="425" height="344">
<param name="movie" value="http://youtube.com/myvideo/"/>
<param name="allowFullScreen" value="true"/>
<param name="allowscriptaccess" value="always"/>
<embed src="http://youtube.com/myvideo/" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>
</object></td>
</tr>
</table>
</ContentTemplate>
</ajax:TabPanel>
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Text;
namespace Backbone.UserControls
{
/// <summary>
/// A component for embedding a Windows Media Player in a web form.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:MediaPlayer runat=server></{0}:MediaPlayer>")]
public class MediaPlayer : System.Web.UI.Control
{
#region Public Properties
private string _fileName = "";
[Bindable(true), Category("Appearance"),
Description("URL to a sound file")]
public string Filename
{
get
{
return _fileName;
}
set
{
_fileName = value;
}
}
private bool _autoStart = true;
[Bindable(true),
Category("Behavior")]
public bool autoStart
{
get
{
return _autoStart;
}
set
{
_autoStart = value;
}
}
private bool _Enabled = true;
[Bindable(true),
Category("Behavior")]
public bool Enabled
{
get
{
return _Enabled;
}
set
{
_Enabled = value;
}
}
private bool _enableContextMenu = true;
[Bindable(true),
Category("Behavior"),
Description("Right-click menu visibility")]
public bool EnableContextMenu
{
get
{
return _enableContextMenu;
}
set
{
_enableContextMenu = value;
}
}
private bool _fullScreen = false;
[Bindable(true),
Category("Behavior")]
public bool fullScreen
{
get
{
return _fullScreen;
}
set
{
_fullScreen = value;
}
}
private int _Balance = 0;
[Bindable(true),
Category("Behavior"),
Description("-100=left, 100=right, 0=balanced (default)")]
public int Balance
{
get
{
return _Balance;
}
set
{
if (value >= -100 && value <= 100) _Balance = value;
else throw new ArgumentException("Value must be between -100 and 100");
}
}
private int _Volume = 100;
[Bindable(true),
Category("Behavior"),
Description("0=mute, 100=full volume (default)")]
public int Volume
{
get
{
return _Volume;
}
set
{
if (value >= 0 && value <= 100) _Volume = value;
else throw new ArgumentException("Volume must be between 0 and 100");
}
}
private int _Loop = 1;
[Bindable(true),
Category("Behavior"),
Description("How many times to replay.")]
public int Loop
{
get
{
return _Loop;
}
set
{
if (value >= 1 && value <= 10000) _Loop = value;
else throw new ArgumentException("Value must be between 1 and 10000");
}
}
private double _Rate = 1;
[Bindable(true),
Category("Behavior"),
Description("Playback speed, 0.5 to 2.0")]
public double Rate
{
get
{
return _Rate;
}
set
{
if (value >= 0.5 && value <= 2) _Rate = value;
else throw new ArgumentException("Value must be between 0.5 and 2.0");
}
}
private bool _Invisible = false;
[Bindable(true),
Category("Appearance"),
Description("If false player will be invisible but can still play.")]
public bool Invisible
{
get
{
return _Invisible;
}
set
{
_Invisible = value;
}
}
private bool _buttonsVisible = true;
[Bindable(true),
Category("Appearance")]
public bool ButtonsVisible
{
get
{
return _buttonsVisible;
}
set
{
_buttonsVisible = value;
}
}
private bool _stretchToFit = true;
[Bindable(true),
Category("Appearance")]
public bool StretchToFit
{
get
{
return _stretchToFit;
}
set
{
_stretchToFit = value;
}
}
private int _Height = 300;
[Bindable(true),
Category("Layout")]
public int Height
{
get
{
return _Height;
}
set
{
if (value >= 0 && value <= 10000) _Height = value;
else throw new ArgumentException("Value must be between 0 and 10000");
}
}
private int _Width = 300;
[Bindable(true),
Category("Layout")]
public int Width
{
get
{
return _Width;
}
set
{
if (value >= 0 && value <= 10000) _Width = value;
else throw new ArgumentException("Value must be between 0 and 10000");
}
}
#endregion
protected override void Render(HtmlTextWriter output)
{
//output begin object tag
StringBuilder sb = new StringBuilder("<OBJECT ID='" +
this.ClientID + "' name='" + this.ClientID + "' " +
"CLASSID='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'" +
"VIEWASTEXT" +
" height=" + _Height + " " + "width=" + _Width +
">");
//Render properties as object parameters
sb.Append("<PARAM name='URL' value='" +
_fileName + "'>");
sb.Append("<PARAM name='AutoStart' value='" +
_autoStart.ToString() + "'>");
sb.Append("<PARAM name='balance' value='" +
_Balance + "'>");
sb.Append("<PARAM name='enabled' value='" +
_Enabled.ToString() + "'>");
sb.Append("<PARAM name='fullScreen' value='" +
_fullScreen.ToString() + "'>");
sb.Append("<PARAM name='playCount' value='" +
_Loop.ToString() + "'>");
sb.Append("<PARAM name='volume' value='" +
_Volume + "'>");
sb.Append("<PARAM name='rate' value='" +
_Rate + "'>");
sb.Append("<PARAM name='StretchToFit' value='" +
_stretchToFit.ToString() + "'>");
sb.Append("<PARAM name='enabledContextMenu' value='" +
_enableContextMenu.ToString() + "'>");
//Determine visibility
if (_Invisible)
{
sb.Append("<PARAM name='uiMode'");
sb.Append(" value='invisible'>");
}
else
{
if (_buttonsVisible)
{
sb.Append("<PARAM name='uiMode'");
sb.Append(" value='full'>");
}
else
{
sb.Append("<PARAM name='uiMode'");
sb.Append(" value='none'>");
}
}
// Now render properties as an embed tag for firefox, netscape, etc.
sb.Append("<EMBED type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'");
sb.Append("id='").Append(this.ClientID).Append("' name='mediaPlayer' ");
sb.Append("displaysize='4' autosize='0' showcontrols='1' showtracker='0' showdisplay='0' showstatusbar='1' videoborder3d='0' ");
sb.Append("width='").Append(_Width).Append("' height='").Append(_Height).Append("' ");
sb.Append("src=\"").Append(_fileName).Append("\" autostart='").Append(_autoStart).Append("' ");
sb.Append("designtimesp='5311' loop='0'></EMBED>");
//output ending object tag
sb.Append("</OBJECT>");
//flush everything to the output stream
output.Write(sb.ToString());
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PlayVideo.aspx.cs" Inherits="PlayVideo" %> <%@ Register Namespace="Backbone.UserControls" TagPrefix="cc" %> <!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" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <%--<cc:mediaplayer id="mediaplayer1" runat="server" filename="Videos/intro.wmv" width="500" height="400" />--%> <%--<cc:mediaplayer id="player1" runat="server" filename="winvideo-cs2k7-ordersextensibility.wmv" width="500" height="400" />--%> <asp:Panel ID="pnl1" runat="server"></asp:Panel> </div> </form> </body> </html>using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Backbone.UserControls; public partial class PlayVideo : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { MediaPlayer mp = new MediaPlayer(); mp.Filename = "Videos/intro.wmv"; //mp.Filename = "WinVideo-CS2K7-OrdersExtensibility.wmv"; pnl1.Controls.Add(mp); } }
Comments
Post a Comment