Solved

Windows Media Player in ASP. NET (VB code behind) webform using Visual Studio .NET?

Posted on 2004-04-28
10
2,036 Views
Last Modified: 2012-08-13
I'm using Visual Studio .NET:

I've used the WMP in a VB windows form before, but can't seem to get the references imported autmatically for AxWMPLib  and WMPLib by dragging the control from the Toolbox to an aspx page in my webform project.

I feel like I must be missing something obvious?

What is the most straightforward way to get a Windows Media Player 9 in an aspx page using Visual Studio .NET with VB code behind?

Thanks!
0
Comment
Question by:majnun
10 Comments
 
LVL 1

Expert Comment

by:vbnewbie01
ID: 10957737
this doesn't answer your question specifically, but since i dabble in video myself, thought i'd pass on the following control information:

http://asp.1host.cl/ControlGallery/ControlDetail.aspx?Control=1340&tabindex=2

download and try it out if your can't find what you're looking for.  otherwise, i'll keep my eyes open.

d.
0
 

Author Comment

by:majnun
ID: 10974026
Looks cool, but I work for a non-profit and I can't justify paying for something that I know WMP can do... and i can hack in some HTML code for the player, but i really was hoping there was some easy way to do it in Visual Studio for webforms, since I can use it in Windows Forms easily... not sure why I can't just drag and drop the player control in my ASPX page.

Hopefully someone will come along with the answer soon.

Thanks for your input!
0
 

Author Comment

by:majnun
ID: 10988338
NEED HELP WITH NEW APPROACH:

[Ok well this sucks, I just paid for Primium service since someone already asked this question, which didn't help because the answer was "forced" essentially said can't use WMP buy the third party control. Whatever, that is a cop out.]

That being said, here's a new approach that someone might be able to help with:

I've added the Windows Media Player to my toolbox for use in other .NET projects. And when I drag it to my ASP page, Visual Studio is smart enough to know its an object, and set up its classID and all the parameters properly. Looks like this in the aspx html view: (note: I manually added the id="player")

<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>

When I view the page in my browser I get the WMP as per normal. But how to program it?

The WMP 9 SDK has the following example:
<HTML>
<HEAD>
</HEAD>
<BODY>
<OBJECT ID="Player" height="0" width="0"
  CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
</OBJECT>
<INPUT TYPE="BUTTON" NAME="BtnPlay" VALUE="Play" OnClick="StartMeUp()">
<INPUT TYPE="BUTTON" NAME="BtnStop" VALUE="Stop" OnClick="ShutMeDown()">
<SCRIPT>
<!--

function StartMeUp ()
{
    Player.URL = "laure.wma";
}

function ShutMeDown ()
{
    Player.controls.stop();
}

-->
</SCRIPT>
</BODY>
</HTML>

CAN SOMEONE SHOW ME HOW TO TRIGGER A SCRIPT LIKE THIS USING A FUNCTION IN THE ASPX.VB CODE BEHIND PAGE?
0
 

Author Comment

by:majnun
ID: 10988344
Increasing points
0
 

Author Comment

by:majnun
ID: 10989994
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:

<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
...
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:majnun
ID: 10990044
NOTE TO ADMINISTRATOR:

Answered my own question, not sure how to proceed. (Though if by the time admin sees this someone has already posted a better solution i will glady accept that).

Thank you!
0
 
LVL 6

Expert Comment

by:gtvingo14
ID: 10997674
post request to PAQ this question at

http://www.experts-exchange.com/Community_Support/
0
 

Author Comment

by:majnun
ID: 11007948
Changed my approach alittle so that instead of creating a client side script in step 3) about do the following:

Call up the page and pass whatever variables you need process in the query string like:
Response.Redirect("thispage.aspx?variable=value")

Then in the HTML of Windows Media Player the aspx page do this:
<OBJECT id="Player" style="Z-INDEX: 105; LEFT: 70%; WIDTH: 29%; POSITION: absolute; TOP: 8px; HEIGHT: 187px" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" VIEWASTEXT>
                  <PARAM NAME="URL" VALUE="<%=getFilename()%>">
...
<OBJECT>

Note that we are calling the getFilename() function... so back in the ASPX.VB page something like:
Function getFilename()
        Dim filename As String

       'Process Variable
       select case Request.QueryString("variable")
            case "value"
                   filename = yourFilename.wav
       end select

        Return filename
End Function

0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 11008217
Closed, 500 points refunded.
PashaMod
Community Support Moderator
0
 

Expert Comment

by:everettwright
ID: 14737689
I was having the same problem, getting the javascript fuction to recognize the wmp object.  I found that you could call the object from javascript by using document.forms[0].mediaplayer where mediaplayer is the name of the wmp, and the wmp is inside the form tags.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>menu2</title>
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
            
            <LINK href="Styles.css" type="text/css" rel="stylesheet">
            <script language="javascript" id="clientEventHandlersJS">
            function goTime(){
            document.forms[0].mediaPlayer.controls.currentPosition = '90';
                  }
            </script>
      </HEAD>
      <body>
      <form id="Form2" method="post" runat="server">
                  <table border="1">
                        <tr>
                              <td><OBJECT id="mediaPlayer" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" name="mediaPlayer" VIEWASTEXT>
                        <PARAM NAME="URL" VALUE="video/cfa_edvd.wmv">
                        <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="6350">
                  </OBJECT></td>
                        </tr></table>
                              <INPUT type="button" value="Button" onclick="goTime();">
            
                  
                  
            </form>
      </body>
</HTML>

Hope this helps someone....
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now