Why doesn't MediaElement work in Silverlight?

百般思念 提交于 2020-01-13 06:06:26

问题


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?


回答1:


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).




回答2:


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.




回答3:


The referenced media files need to be in ClientBin folder. For Sliver-light 4.0 you may use not only .wmv but .mp4 format as well.




回答4:


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.




回答5:


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.




回答6:


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



来源:https://stackoverflow.com/questions/478017/why-doesnt-mediaelement-work-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!