views:

80

answers:

2

How do yo play a video with silverlight?

does Visual Studio come with a video player component build in? or do I need to make a video player?

A: 

In SL:

<MediaElement x:Name="MyVid"
              Source="http://abc.xyz.com/MyVid.wmv"
              Height="250"
              Width="350"
              AutoPlay="True"/>

Server-side needs to support MMS (RTSP protocol - streaming) or progressive downloads (MMS on the MediaElement's side takes care of both). Videos should conform to the SMPTE 421M video codec standard (VC-1).

Jaroslav Jandek
Are you sure about the server needing to support mms? I didn't think it was needed, won't it just download the file of the server, "progressive download" style?
Ola Karlsson
@Ola Karlsson: I have not used this code in years. If I remember correctly, seeking did not work when using a non-MMS url... I simply used the MMS service and all was working fine.
Jaroslav Jandek
"Server-side needs to support MMS (Microsoft Media Server) protocol."I thought only the server that host the sliverlight needs this, the site that players the file also needs it?
K001
@Khou: Well, the client uses MMS (RTSP). Server needs to support being requested that way (most do out of the box). Basically it's just UDP/TCP progressive download from the sever's point of view or you can use regular streaming via `Windows Media Services` (on the server). Also note that your video files should use the **SMPTE 421M** video codec standard.I have edited the answer so it's less confusing (I hope) in regards to MMS.
Jaroslav Jandek
+2  A: 

As often is the case, it depends what you're requirements are.

You can use the media element which comes with Silverlight (msdn info here) , however, that means building everything from scratch, it does not come with a "player chrome", as in buttons and visual styles.

If you want a pre-built "player", there's at least a couple of options, the Expression Encoder tool (a free version is available), comes with a number of Silverlight players that you can freely use and modify if you wish. You find them under the "templates" section in expression encoder tool.

Another option is to use the Silverlight Media Framework (SMF), which is a open source project which Microsoft is involved in, it comes with a fully featured "player" and is built on industry standards, you can find it at http://smf.codeplex.com.

Good luck!

Ola Karlsson
Actually, the `MediaElement` is a player. It just does not have any controls (which you may want in some cases). I see being simplistic as an advantage of the control. You can very easily add control buttons / info text in a few lines of code anyway.
Jaroslav Jandek
Good point, I've updated my post to make it clearer what I mean by a "player".
Ola Karlsson
SMF is one of the better players in my opinion - and certainly a good starting point if you are creating your own.
Goyuix