Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Playing the media file using Asp:MediaPlayer RSS

3 replies

Last post Mar 10, 2009 05:13 AM by DaveCS

(0)
  • devadkarramesh

    devadkarramesh

    Member

    5 Points

    19 Posts

    Playing the media file using Asp:MediaPlayer

    Oct 16, 2008 11:34 AM | LINK

    I have the <Asp:MediaPlayer id="media"> on the aspx page.

    when i directly set  <Asp:MediaPlayer id="media" MediaSource="~/test.wmv"> it is playing the video

    I would like to set the MediaSource property of the media element from the silverlight code

    I am  doing like

    HtmlElement ele = HtmlPage.Document.GetElementById("media")

    ele.SetAttribute("mediaSource","test.wmv");

     

    but it is not playing the  video

    i even tried with "Source",MediaSource"

     How to set teh attribute of media player to play the file??

    Ramesh Devadkar
    Dotnet Developer

    Dont forget to click “Mark as Answer” on the post that helped you.
    This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers
  • amit_pal1979

    amit_pal1979

    Participant

    1150 Points

    202 Posts

    Re: Playing the media file using Asp:MediaPlayer

    Oct 16, 2008 12:24 PM | LINK

    What happens if you copy this video file to ClientBin folder?

     

    Please mark the post as 'Answered' if this Answers your question

  • Jonathan Shen – MSFT

    Jonathan She...

    All-Star

    50156 Points

    4951 Posts

    Microsoft

    Re: Playing the media file using Asp:MediaPlayer

    Oct 22, 2008 09:37 AM | LINK

    Hi DevadKarramesh,

    devadkarramesh

    ele.SetAttribute("mediaSource","test.wmv");

    It doesn't work.  To achieve your purpose, please write a javascript function to your aspx page and call it on Silverlight code behind.  For example,

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="ComboBoxTest.Web.test" %>

    <%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"
        TagPrefix="asp" %>

    <!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></title>
    </head>
    <body>
        <form id="form1" runat="server">
         <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div>
            <asp:MediaPlayer ID="media" runat="server" Height="240px" Width="320px" MediaSource="~/ClientBin/WinVideo-Silverlight-2b2-InStateAnimation.wmv" >
            </asp:MediaPlayer>
            <input id="Button1" type="button" value="button" onclick="changeMedia();"/>
        </div>
             <script type="text/javascript" language="javascript">
                 function changeMedia() {
                     //$find('media').play();
                     $find('media').set_mediaSource("/ClientBin/Winvideo-SL-FontEmbed.wmv");
                     $find('media').play();
                 }
             </script>  
        </form>
    </body>
    </html>

    To find more functions, please take a look at SilverlightMedia.debug.js.  To get this file,  we can go through its generated HTML code.

    <script src="/ScriptResource.axd?d=tDheqULHr2DXn2x-sTKlw78T9mUlLdYYuz3y2jsQcHNwDtUnJF3eUUqsYCqBrquGvcdf8k02CO4zqRehDqCpxw2&amp;t=11400759" mce_src="/ScriptResource.axd?d=tDheqULHr2DXn2x-sTKlw78T9mUlLdYYuz3y2jsQcHNwDtUnJF3eUUqsYCqBrquGvcdf8k02CO4zqRehDqCpxw2&amp;t=11400759" type="text/javascript"></script>

    Then download the file by typing  http://localhost:5978/ScriptResource.axd?d=tDheqULHr2DXn2x-sTKlw78T9mUlLdYYuz3y2jsQcHNwDtUnJF3eUUqsYCqBrquGvcdf8k02CO4zqRehDqCpxw2&amp;t=11400759.   The file can be opened by notepad, editplus etc.

    Best regards,

    Jonathan

    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
  • DaveCS

    DaveCS

    Member

    116 Points

    69 Posts

    Re: Re: Playing the media file using Asp:MediaPlayer

    Mar 10, 2009 05:13 AM | LINK

     Very nice info. I started off with vb4 had all versions of vs and never knew until today that those debug files were useful.

    Thanks!