In ASP.Net having Windows Media Player With VB.Net?
Hi,
In ASP.Net having Windows Media Player With VB.Net?
I have this page in ASP.Net & I have placed windows Media player in it.
Now what I am looking for is there any way i can send the Play Command to the WMP from the code behind file (VB.NEt)?
AND
I want to know the controls of the player & player.controls.currentPosition value
Please help me with the same!
Re: In ASP.Net having Windows Media Player With VB.Net?
I'm building a section of a website to show streaming videos. There's a lot more logic involved, but the jist of it all is the video id is pulled as a session variable, but before the video is played, a random ad is played beforehand (based on the topic of the video).
I use 3 pages for this.
The main .aspx page has the following:
Code:
<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" id="VIDEO" type="video/x-ms-asf"
width="400" height="365" standby="Loading Microsoft Windows Media Player components..."
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715">
<param name="StretchToFit" value="1" />
<param name="AutoStart" value="true" />
<param name="Balance" value="0" />
<param name="EnableContextMenu" value="1" />
<param name="Enabled" value="1" />
<param name="EnableErrorDialogs" value="1" />
<param name="WindowlessVideo" value="0" />
<param name="Rate" value="1.000" />
<param name="CurrentPosition" value="0.000" />
<param name="CurrentMarker" value="1" />
<param name="FullScreen" value="0" />
<param name="Mute" value="0" />
<param name="PlayCount" value="1" />
<param name="Uimode" value="Full" />
<param name="Volume" value="50" />
<param name="URL" value ="<%Response.Write(strPlay) %> "/>
<embed id="mpFAB" type="video/x-ms-asf" src="<%Response.Write(strPlay) %>" width="400" height="345"
showcontrols="1" />
</object>
The code behind (.aspx.vb) sets the variable for the URL after several queries as such:
Code:
strPlay = "/MediaList.aspx?u=" & (strUnderwriter) & "&ut=" & (strUTitle) & "&v=" & (strURL) & "&vt=" & (strVTitle)
Finally, the playlist (MediaList.aspx) contains the following code:
Code:
<%@ Page Language="VB" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strUnderwriter As String
strUnderwriter = Request.QueryString("u")
Dim strURL As String
strURL = Request.QueryString("v")
Dim strUTitle As String
strUTitle = Request.QueryString("ut")
Dim strVTitle As String
strVTitle = Request.QueryString("vt")
Response.ContentType = "video/x-ms-asf"
Response.Expires = 0
Response.Write("<ASX version=""3.0"">")
Response.Write("<ENTRY CLIENTSKIP=""NO"">")
Response.Write("<TITLE>" & (strUTitle) & "</TITLE>")
Response.Write("<COPYRIGHT> 2008 </COPYRIGHT>")
Response.Write("<ref href = """ & (strUnderwriter) & """ />")
Response.Write("</ENTRY>")
Response.Write("<ENTRY>")
Response.Write("<TITLE>" & (strVTitle) & "</TITLE>")
Response.Write("<ref href =""" & (strURL) & """ />")
Response.Write("<COPYRIGHT> 2008 </COPYRIGHT>")
Response.Write("</ENTRY>")
Response.Write("</ASX>")
End Sub
</script>
Re: In ASP.Net having Windows Media Player With VB.Net?
See this page to embed media player in web project!
http://www.codeproject.com/KB/aspnet/WMPnFlash.aspx
Re: In ASP.Net having Windows Media Player With VB.Net?
Ok, here's the solution I have come up with:
Here are the key points to get it to work (lots of trial and error went into my discovering this):
1) YOU MUST HAVE THE OBJECT TAGS REPRESENTING THE PLAYER, ABOVE THE <Form></Form> Tags that Visual Studio creates in the ASPX page. You must MANUALLY edit the HTML of the aspx, then simply cut <object></object> tags (and everything between them) and past them in the code above the <form> tag
Like so:
Code:
<OBJECT id="Player1" style="Z-INDEX: 104; LEFT: 337px; WIDTH: 245px; POSITION: absolute; TOP: 9px; HEIGHT: 176px" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" VIEWASTEXT>
<PARAM NAME="URL" VALUE="">
<PARAM NAME="rate" VALUE="1">
<PARAM NAME="balance" VALUE="0">
<PARAM NAME="currentPosition" VALUE="0">
<PARAM NAME="defaultFrame" VALUE="">
<PARAM NAME="playCount" VALUE="1">
<PARAM NAME="autoStart" VALUE="-1">
...
</OBJECT>
<FORM id="Form1" method="post" runat="server">
...
[The important thing here is that the Object representing the media player is outside the <Form> tags which get run at the server]
2) You need to manaully add: id="Player1" to the <object tag>
3) You then create a server side script that references the id created in step 2) like: Player.URL = filename.wav
3a) create a button or some trigger that launches that script
For my own script I wanted to set the value of the filename dymanically based on a date field coming from a datagrid. So I created an image button in a template column in the datagrid:
<asp:TemplateColumn HeaderText="Play">
<HeaderStyle Width="1%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<asp:ImageButton id="PlayButton" runat="server" ImageUrl=".\images\playbutton.bmp" CommandName="play" AlternateText="Play" ImageAlign="Middle"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
[the important thing here is that the CommandName is "play" which is in the aspx.vb code behind page:]
Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
Select Case e.CommandName
Case "play"
Dim path, filename As String
path = PathToWMAs 'this is a form wide string variable set elsewhere
filename = Format(CDate(e.Item.Cells(2).Text), "MMddyy") & ".wma"
filename = Server.UrlPathEncode(path & filename)
TextBox1.Text = filename
'create the script that gets triggered by the <Body> tag's OnLoad parameter
Dim strScript As String
strScript = "<script language=JavaScript>"
strScript = strScript + "function playMe()"
strScript = strScript + "{"
strScript = strScript + "Player1.URL =""" & filename & """;"
strScript strScript + "return confirm(""" & filename & """);"
strScript = strScript + "}"
strScript = strScript + "</script>"
Page.RegisterStartupScript("ClientScript", strScript)
End Select
End Sub
[Important thing here to note is that 1) I used the RegisterStartUpStript to create a script after the form HTML is spit out by server which allows me to change which filename gets loaded dynamically 2) the function i thus created is called by the body's onLoad parameter:]
<BODY onLoad="playMe()" MS_POSITIONING="GridLayout">
---------------------------------------SAMPLE CODE FROM MY WORKING PROJECT-------------------------------
To help others who may be in a similar situation as myself, I will paste all the pertinet code straight from my project:
[ASPX PAGE - non-pertinent code omitted]-------------------------------------------------------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="audioarchives.aspx.vb" Inherits="bahairadio.audioarchives"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>audioarchives</title>
<META content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<META content="Visual Basic 7.0" name="CODE_LANGUAGE">
<META content="JavaScript" name="vs_defaultClientScript">
<META content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<BODY onLoad="playMe()" MS_POSITIONING="GridLayout">
<OBJECT id="Player1" style="Z-INDEX: 104; LEFT: 337px; WIDTH: 245px; POSITION: absolute; TOP: 9px; HEIGHT: 176px" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" VIEWASTEXT>
<PARAM NAME="URL" VALUE="">
<PARAM NAME="rate" VALUE="1">
<PARAM NAME="balance" VALUE="0">
<PARAM NAME="currentPosition" VALUE="0">
<PARAM NAME="defaultFrame" VALUE="">
<PARAM NAME="playCount" VALUE="1">
<PARAM NAME="autoStart" VALUE="-1">
<PARAM NAME="currentMarker" VALUE="0">
<PARAM NAME="invokeURLs" VALUE="-1">
<PARAM NAME="baseURL" VALUE="">
<PARAM NAME="volume" VALUE="50">
<PARAM NAME="mute" VALUE="0">
<PARAM NAME="uiMode" VALUE="full">
<PARAM NAME="stretchToFit" VALUE="0">
<PARAM NAME="windowlessVideo" VALUE="0">
<PARAM NAME="enabled" VALUE="-1">
<PARAM NAME="enableContextMenu" VALUE="-1">
<PARAM NAME="fullScreen" VALUE="0">
<PARAM NAME="SAMIStyle" VALUE="">
<PARAM NAME="SAMILang" VALUE="">
<PARAM NAME="SAMIFilename" VALUE="">
<PARAM NAME="captioningID" VALUE="">
<PARAM NAME="enableErrorDialogs" VALUE="0">
<PARAM NAME="_cx" VALUE="6482">
<PARAM NAME="_cy" VALUE="4657">
</OBJECT>
<FORM id="Form1" method="post" runat="server">
... [various other items on page, a calender view, etc. not important to current discussion]
<asp:datagrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 6px; POSITION: absolute; TOP: 262px" runat="server" PageSize="31" AutoGenerateColumns="False" CellPadding="2" Width="100%">
... [various datagrid parameters not important to current discussion]
<Columns>
<asp:TemplateColumn HeaderText="Play">
<HeaderStyle Width="1%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<asp:ImageButton id="PlayButton" runat="server" ImageUrl=".\images\playbutton.bmp" CommandName="play" AlternateText="Play" ImageAlign="Middle"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>
... [Various other columns pulling from database not important to current discussion]
<asp:BoundColumn DataField="date" SortExpression="date" HeaderText="Date" DataFormatString="{0:d}">
<HeaderStyle Width="1%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
</asp:BoundColumn>
... [Various other columns pulling from database not important to current discussion]
</Columns>
</p>
</FORM>
</P>
</BODY>
</HTML>
[ASPX.VB non-pertinent code omitted]-----------------------------------------------
...
Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
Select Case e.CommandName
Case "play"
Dim path, filename As String
path = PathToWMAs
filename = Format(CDate(e.Item.Cells(2).Text), "MMddyy") & ".wma"
filename = Server.UrlPathEncode(path & filename)
TextBox1.Text = filename
'create the script that gets triggered by the <Body> tag's OnLoad parameter: <body onLoad="playMe()" ... >
Dim strScript As String
strScript = "<script language=JavaScript>"
strScript = strScript + "function playMe()"
strScript = strScript + "{"
strScript = strScript + "Player1.URL =""" & filename & """;"
strScript &= "return confirm(""" & filename & """);"
strScript = strScript + "}"
strScript = strScript + "</script>"
Page.RegisterStartupScript("ClientScript", strScript)
End Select
...
Re: In ASP.Net having Windows Media Player With VB.Net?
You can either user <img> or <object> to embed movies in *.aspx. But to capture the events, you should use the later
Use the below <object tag> to embed WMP in .aspx / html pages
Code:
<object id="VIDEO" width="100%" height="100%"
classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
type="application/x-oleobject">
<param name="URL" value="http://localhost/QaQcTraining/movies/start.wmv" />
<param name="SendPlayStateChangeEvents" value="True" />
<param name="AutoStart" value="True" />
<param name="uiMode" value="none" />
<param name="windowlessVideo" value="True" />
<param name="stretchToFit" value="true" />
</object<
Now, use the below script to capature the events of WMP
<script language=jscript FOR = VIDEO EVENT = playStateChange(NewState) type=text/jscript>
// Test for the player current state, display a message for each.
switch (NewState){
case 1:
//myText.value = "Stopped";
//alert('stoped');
location.href="qform.aspx";
//redirecting to different page after the movie plays
break;
case 2:
//myText.value = "Paused";
//alert('paused');
break;
case 3:
//myText.value = "Playing";
//alert('playing');
break;
// Other cases go here.
default:
//alert('def');
//myText.value = "";
}
</script>
Re: In ASP.Net having Windows Media Player With VB.Net?
Hi,
I need to play list of mp3 files(using URLS) in my C# Web application.
How to pass that array to the player?
Please respond.
Thanks in advance
Sireesha