danthehat
danthehat

Reputation: 99

MediaElement.IsLoaded Lies

So I've created a slideshow. The slideshow uses two overlapping media elements which display pictures. A transition simply means decrementing opacity of the foreground element and incrementing the opacity of the background element.

The problem is a picture is not loaded into the media element fast enough. This causes stuttering and generally looks bad. I got the idea that I could just create a tight loop that looks at the MediaElement.IsLoaded property until it becomes true. It turns out that isLoaded is always true because IsLoaded considers the media element, not the source.

I also thought about MediaElement.DownloadProgress, but it lies too.

Thoughts?

Upvotes: 2

Views: 1973

Answers (1)

Rick Sladkey
Rick Sladkey

Reputation: 34240

The Loaded event and the IsLoaded property are general features of all WPF controls derived from FrameworkElement. The IsLoaded property becomes true and the Loaded event is raised when the element is added to the visual tree, not when the content of the element has been displayed. So IsLoaded is the wrong property for what you are trying to detect.

The Loaded event is described like this:

Loaded is usually the last event raised in an element initialization sequence.

On the other hand, MediaElement has an event that might meet your needs:

which is described like this:

Occurs when the media stream has been validated and opened, and the file headers have been read.

This sounds like the correct event for your application.

Upvotes: 8

Related Questions