Setting a MediaElement Source to a StorageFile

February 21, 2013

tips word in wood type

In a previous post I mentioned I’m working on an app that plays videos. The app is pretty simple and fits a specific need I have. Once it’s in the Windows Store I’ll give the full details on it. In the meantime I want to share some tips and tricks I learn along the way that might help you with your app. These aren’t ground breaking revelations into Windows Store app development, they’re just things I found useful and wanted to pass along.

In that previous post I showed you how to create a bitmap image from a file that you could then use in your UI. In this post I’ll show you how to get set a MediaElement’s source to a file so it can be played within your app. As you’ll see in a moment it’s incredibly simple, you just need to open the file to get its stream and then set the source of the MediaElement to the stream. Just like this:

That’s it. Like I said above, nothing groundbreaking or innovative, just a handy tip that might come in useful. Hope it helps.