views:

4096

answers:

7

When I run my Silverlight app, this code doesn't play a video at all:

    <MediaElement
        Source="winvideo-201DataGridPreview.wmv"
        AutoPlay="True"
        AudioStreamIndex="2"
        Margin="10"
        Height="200"
        Width="200"/>

From all of the examples I can find of MediaElement, it seems to be the correct syntax, etc.

Is there anything I'm forgetting?

A: 

Are you sure the video file gets copied to the bin/Debug directory?

texmex5
yes, I switched it to "copy always", I've trie a .avi file and a .wmv file, moved them to the root and tried them, always just blank, no sound. Hmmmm.
Edward Tanguay
A: 

Are you getting anything in the Output window when you F5 it?

Steven Robbins
A: 

It might be the case of unsupported mediafile.

These are supported (source: http://msdn.microsoft.com/en-us/library/cc189080(VS.95).aspx)

The MediaElement object supports the following formats. These encodings are supported regardless of the file name extension.

Video

  • WMV1: Windows Media Video 7
  • WMV2: Windows Media Video 8
  • WMV3: Windows Media Video 9
  • WMVA: Windows Media Video Advanced
  • Profile, non-VC-1
  • WMVC1: Windows Media Video Advanced Profile, VC-1

Audio

  • WMA 7: Windows Media Audio 7

  • WMA 8: Windows Media Audio 8

  • WMA 9: Windows Media Audio 9

  • WMA 10: Windows Media Audio 10

  • MP3: ISO/MPEG Layer-3

    • Input: ISO/MPEG Layer-3 data stream

    • Channel configurations: mono, stereo

    • Sampling frequencies: 8, 11.025, 12, 16, 22.05, 24, 32, 44.1, and 48 kHz

    • Bit rates: 8-320 kbps, variable bit rate

    • Limitations: "free format mode" (see ISO/IEC 11172-3, sub clause 2.4.2.3) is not supported.

On really simple (but a bit brute force) way to test if your video file is Silverlight compatible is to upload it to http://Silverlight streaming and it will tell you if it is ok or not.

texmex5
+1  A: 

Edward, based on your XAML check: 1) that the WMV file is in the appropriate encoding format, 2) that the WMV file is located alongside where your XAP file is (I'd actually check this first).

Tim Heuer
A: 

I'm getting the same issue, I haven't found the right configuration that will reference the video file correctly. If I reference my video by source "vid1.wmv" and set it to content, it's packaged into the xap file but the video won't play.

As TimHeuer says, check the video file is in the same place as the .xap file.

If I copy the video file directly into the web project's ClientBin, it works. That was the solution for me, but I'd really like to know how this should be done correctly.

TreeUK
+1  A: 

I had a similar problem. I added the wmv file as an existing object to my Silverlight project, and then on the properties of the wmv file, I set its build action to Resource. Once I did this it would play for me.

Daniel
A: 

This was very annoying but found that if you right click on your media file and properties and set it to "Content" build action it will be included in the XAP, then you reference it with /myPic.jpg/wmv or /Images/myPic.jpg/wmv (depending on the structure of your project and vid or pic obviously). Hope this helps