开发者

MediaElement not displaying

开发者 https://www.devze.com 2023-02-11 09:53 出处:网络
I\'ve placed a MediaElement on a newly created window in an application we\'re building, set the source of it a wmv (also tried it with a gif), but it doesn\'t show up on the screen when I run it.

I've placed a MediaElement on a newly created window in an application we're building, set the source of it a wmv (also tried it with a gif), but it doesn't show up on the screen when I run it.

I then created a new separate project and it all works as expected.

this is the code that works:

<MediaElement Source="pre-loader.wmv" LoadedBehavior="Manual" Name="Video" />

and this is the code that doesn't work:

<MediaElement Source="pre-loader.wmv" LoadedBehavior="Manual" Name="Video" />

I know, its the same... I dont get it?

I have tried a couple of different ways but I get the same result. The test project works main application doesn't.

I am using the same wmv file in both projects, I also made sure that in both cases the Copy to Output dir. is set to Copy if New开发者_运维问答er.

Any help would be... well, helpfull

Update: I have tried looking for the MediaElement using snoop and the ActualWidth, ActualHeigt are both 0 but the height property is 140 and the width property is NAN. Also, the source = Default.

I'm also getting "Error occured loading preview" when I look at the screen in Blend, but it doesnt let me what the error is.


The first place to look is in your project resources. The "Source" property indicates that you are getting the video from a relative URI, which only works when the video is located in your project's files.

MediaElement by default has a silent fail, meaning it will not throw an exception unless you program it to specifically. This is usually set with some sort of action in the Mediaelement's "MediaFailed" (VB)/"OnMediaFailed" (C#) property in code behind. I usually put a messagebox into this event to tell the user that the video could not load.

In the project that you are having the problems in, the first thing you need to do is go into the project properties, go to the "Resources" tab, and import the video as a resource. Then, in the Solution Explorer, click on the video (in the Resources folder) and (as you have done) set its properties to BuildAction = None and CopyToOutput = Copy if newer. Do NOT set it to "Embedded Resource", or the MediaElement will not be able to play it. It HAS to be set to "None".

Then, change the mediaelement source to "Resources/pre-loader.wmv"

The other (rather obvious) piossiblity is checking if you are calling the mediaelement.play function in your code behind. If you don't need to explicitly control the play/pause/stop functions, I would set the the LoadedBehavior to "play".

Hope that helps! Comment if you have any more questions.


Check the "Platform tagret" property of both projects in projects properties. Some codecs works only in x86 or x64 mode.

0

精彩评论

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