开发者

Playing video using Silverlight

开发者 https://www.devze.com 2023-01-09 08:00 出处:网络
Here I am new to Silverlight and I have to implement a video player in asp.net with C# , I found some article about video player and media player. I am implementing according the tutorials but the tha

Here I am new to Silverlight and I have to implement a video player in asp.net with C# , I found some article about video player and media player. I am implementing according the tutorials but the that is not working here I am sending my code please find out what is problem. Tell me what is the difference between media element and media player in Silverlight?

here is the code of .aspx page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<%@ Register assembly="AjaxControlToolkit" amespace="AjaxControlToolkit"  tagprefix="cc1" %>    


<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>SILVERLIGHT MEDIA PLAYER | DEMO</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="xx" runat="server"></div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />    

            <div>
                <div style="float:left">
                    <asp:DropDownList ID="cmbSkins" runat="server" 
                    onselectedindexchanged="cmbSkins_SelectedIndexChanged" />
                </div>               
                <div><h3>SELECT PLAYER STYLE</h3></div>
            </div>

            <asp:MediaPlayer ID="MediaPlayer1" runat="server" 
                Width="600px" 
                Height="440px"
                PlaceholderSource="http://www.webinfocentral.com/VIDEO/JJ2008/ImgMain.JPG">                  
            </asp:MediaPlayer>
            <hr />            
            <hr />    
        </form>
    </body>
</html>

and this the code behind page:

public partial class _Default : System.Web.UI.Page
{
protected enum MediaPlayerSkins
{
    AudioGray,
    Basic,
    Classic,
    Console,
    Expression,
    Futuristic,
    Professional,
    Simple
}   

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        MediaPlayer1.AutoPlay = true;
        MediaPlayer1.ScaleMode = System.Web.UI.SilverlightControls.ScaleMode.Zoom;

        cmbSkins.Items.Add(MediaPlayerSkins.Classic.ToString());
        cmbSkins.Items.Add(MediaPlayerSkins.Console.ToString());
        cmbSkins.Items.Add(MediaPlayerSkins.Expression.ToString());
        cmbSkins.Items.Add(MediaPlayerSkins.Futuristic.ToString());
        cmbSkins.Items.Add(MediaPlayerSkins.Professional.ToString());
        cmbSkins.Items.Add(MediaPlayerSkins.AudioGray.ToString());
        cmbSkins.Items.Add(MediaPlayerSkins.Simple.ToString());
        cmbSkins.AutoPostBack = true;
        cmbSkins.SelectedIndex = 4;

        MediaPlayer1.Med开发者_如何转开发iaSource = Server.MapPath("~/") + "Wildlife.wmv";
        xx.InnerHtml = Server.MapPath("~/") + "Wildlife.wmv";
        MediaPlayer1.MediaSkinSource = "~/MediaPlayerSkins/" + cmbSkins.SelectedValue + ".xaml";
    }
}


protected void cmbSkins_SelectedIndexChanged(object sender, EventArgs e)
{
    MediaPlayer1.MediaSkinSource = "~/MediaPlayerSkins/" + cmbSkins.SelectedValue + ".xaml";
}

}

I don't know anything about Silverlight and this is done using a article, I only changed the source of player nothing else and this is not working.

One question is arising in my mind that which is the best for playing video flash player or this one while we have a low bandwidth internet connection. Please tell me some useful solution?

Thanks


To answer this part of your question:

tell me what is the difference between media element and media player in silver light.

The MediaPlayer element you've used is an ASP.NET control which consists of a basic Silverlight player (using Silveright 1.0 I think). All you have to do is point it at the video file and it will play. The MediaPlayer gives you all the basic controls for playing media (play/pause, etc).

A MediaElement is a Silverlight type used in a Silverlight application, not an ASP.NET application like the MediaPlayer. MediaElements are used in XAML (i.e. Silverlight markup) to represent, well, media elements. The MediaElement doesn't give you controls for playing the media, it just renders it (whether audio or visual). You can use other elements in XAML to control the MediaElement, e.g. if you wanted a play/pause button, you could create another element to do that.


guys i found why it was not working i am missing the proper source path that should be "~/MediaFile.wmv" instead of server.mappath(....).

0

精彩评论

暂无评论...
验证码 换一张
取 消