Oct 112012
 October 11, 2012  Posted by at 9:12 am WinRT  Add comments

Playing sounds, music or videos in a Windows Store App is pretty easy. Here is how you can do it.

Play Video Or Music Windows Store App

Play Video Or Music Windows Store App

I’ve added a folder for the files
Play Video Or Music Windows Store App

The View – the styles for the buttons can be found in teh standardstyles resource dictionary, but Ive added them here for simplicity


    <Border BorderThickness="6" BorderBrush="White" Width="500" Height="400" >
    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Background="Black">
            <Style x:Key="PlayAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}">
                <Setter Property="AutomationProperties.AutomationId" Value="PlayAppBarButton"/>
                <Setter Property="AutomationProperties.Name" Value="Play"/>
                <Setter Property="Content" Value="&#xE102;"/>
                <Style x:Key="PauseAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}">
                    <Setter Property="AutomationProperties.AutomationId" Value="PauseAppBarButton"/>
                    <Setter Property="AutomationProperties.Name" Value="Pause"/>
                    <Setter Property="Content" Value="&#xE103;"/>
        <MediaElement x:Name="myMediaElement" Height="300" Width="500"/>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,20,0,0">
                <Button x:Name="play" Style="{StaticResource PlayAppBarButtonStyle}" Click="play_Click"/>
                <Button x:Name="stop" Style="{StaticResource PauseAppBarButtonStyle}" Click="stop_Click"/>

The code

using System;
using Windows.ApplicationModel;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace PlaySound

    public sealed partial class MainPage : Page
        public MainPage()

        protected override async void OnNavigatedTo(NavigationEventArgs e)
            StorageFolder folder = await Package.Current.InstalledLocation.GetFolderAsync("VideoAndMusic");
            StorageFile file = await folder.GetFileAsync("IrisDevReach.mp4");
            var stream = await file.OpenAsync(FileAccessMode.Read);

            myMediaElement.SetSource(stream, file.ContentType);

        private void play_Click(object sender, RoutedEventArgs e)

        private void stop_Click(object sender, RoutedEventArgs e)

7 comments on “Playing sound, music or video in Windows Store Apps

  1. Pingback: Windows 8 Developer Links – 2012-10-12 | Dan Rigby

  2. Pingback: Playing sound, music or video in Windows Store Apps

  3. Pingback: Dew Drop – October 12, 2012 (#1,421) | Alvin Ashcraft's Morning Dew

  4. Farhan Ghumra on said:

    Hi, myMediaElement.SetSource(stream, file.ContentType) starts playing the media how can I stop that ?

  5. srikanth on said:

    how to play you tube video in windows store applications

    • Iris Classon on said:

      I believe this answers yoru question: http://stackoverflow.com/questions/15678501/stream-youtube-video-in-mediaelement-windows-store-app

      Make sure to upvote the kind dev that answered the question there :) Thank you for visiting the blog and asking questions! Take care

Leave a Reply

Your email address will not be published. Required fields are marked *


HTML tags are not allowed.

What is 7 + 9 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)