Solved

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

Posted on 2004-04-28
10
2,053 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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
 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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