MediaElement in 3DTools

Topics: User Forum
Feb 5, 2007 at 9:22 AM
The MediaElement totally messes up things in 3DTools. As soon as you MouseOver the playing MediaElement, the player goes blank and when you hover away from it it restarts from the beginning.

Any way to overcome this?
Coordinator
Feb 6, 2007 at 10:51 PM
What are you setting the properties to on MediaElement? I did a quick test with this:

<MediaElement Source="c:\videos\FrameworkElement3D.wmv" Name="myMediaElement"
Width="450" Height="250" LoadedBehavior="Play" UnloadedBehavior="Stop" Stretch="Fill"/>

and got it to work.

If I set the LoadedBehavior to "Manual" though, and then play the video on the MediaOpened event, I can get it to restart from the beginning depending on what I mouse over.

What I imagine is happening in your case, is whatever you are using to play/stop the video is having problems with the tricks we're doing behind the scenes to fake the 2D interaction. Behind the scenes, we keep the current 2D object you're interacting with in the hidden layer, as well as the previous one you interacted with (there also is one for keyboard focus, so possibly 3 total). So when you move over a new 2D on 3D object, something is getting moved out of the primary hidden visual to the old one, and the new thing you moved over goes to the primary hidden visual. This hidden swapping unfortunately though can cause problems with Loaded type events (as they fire when it gets added/removed from the hidden layer), which I imagine is what you're running in to.

There's a quick description of this same thing (although relating to triggers) in the README, but the workaround is to just keep everything in that hidden layer, rather than just keeping the most recent ones. It requires writing some code, but shouldn't be too much. The other trick is to just avoid Loaded type events.

The above is all my guess though, so let me know how you're using MediaElement, and if the above description makes sense.

-Kurt
Feb 7, 2007 at 6:00 AM
My previous post wsan't so clear about the issue. Anyway, I am using the InteractiveViewport3DSample sample and have modified the code as

<!-- Second UI -->
<Canvas x:Key="UI2" Background="Green">
<MediaElement Source="e:\\code4bill.wmv">

</MediaElement>
</Canvas>

As long as I am on the MediaElement, it works fine. But as soon as I mouse over any other object in the scene, the video restarts. I guess this might be because the MediaElement seems to restart whenever it is included in the visual tree, is it?

Any way this can be avoided without too much perf. penalty?
Coordinator
Feb 15, 2007 at 3:13 AM
Yeah, I think the restart is happening due to the movement happening behind the scenes in the Visual tree to get the 2D on 3D to work.

I think if you set the LoadedBehavior to Manual, and then just start playing the video when the Viewport3D gets loaded (or any other event) it should work, since in this case the video isn't linked to whether or not the Visual it's on is in the Visual tree. Your other option is to just never remove (or move around) the 2D on 3D Visuals you mouse over. This would require some changes to 3DTools itself. It wouldn't be a big change, but probably would end up being more work than the first method.

-Kurt