Introduction
Windows 8 Apps have a good control for playing audio & videos in applications. I have integrated a Media Control in this sample and used several methods to make it work.
To embed a music or video player in your application we use the “MediaElement class”. I also created customized controls to give more functionality such as play, pause, volume +, Volume – and Stop.
You can use also “enable full-screen mode” when you use a video. I used the MediaElement class to control and manage audio media playback in a Windows Store app using C#.
In this sample the MediaElement class has the following methods:
- Pause: Pauses media at the current position.
- Play: Plays media from the current position.
- Stop: Stops and resets media to be played from the beginning.
The MediaElement class has these properties:
IsMuted Gets or sets a value indicating whether the audio is muted.
Volume Gets or sets the media’s volume.
Description
I’ve used Visual Studio Ultimate 2012 and used the following 5 buttons:
| Button | Click handler action |
| Play | Calls the Play method. |
| Pause | Calls the Pause method. |
| Stop | Calls the Stop method. |
| Vol – | Volume Down |
| Vol + | Volume Up |
And one MediaElement (Name property: Media).
C# Code
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using Windows.Foundation;
- using Windows.Foundation.Collections;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Controls.Primitives;
- using Windows.UI.Xaml.Data;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Navigation;
- // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
- namespace Music_Player
- {
- /// <summary>
- /// An empty page that can be used on its own or navigated to within a Frame.
- /// </summary>
- public sealed partial class MainPage : Page
- {
- public MainPage()
- {
- this.InitializeComponent();
- }
- /// <summary>
- /// Invoked when this page is about to be displayed in a Frame.
- /// </summary>
- /// <param name="e">Event data that describes how this page was reached. The Parameter
- /// property is typically used to configure the page.</param>
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- Media.Play();
- }
- private void Button_Click_2(object sender, RoutedEventArgs e)
- {
- Media.Pause();
- }
- private void Button_Click_3(object sender, RoutedEventArgs e)
- {
- Media.Stop();
- }
- private void Button_Click_4(object sender, RoutedEventArgs e)
- {
- if (Media.IsMuted)
- {
- Media.IsMuted = false;
- }
- if (Media.Volume > 0)
- {
- Media.Volume -= .1;
- }
- }
- private void Button_Click_5(object sender, RoutedEventArgs e)
- {
- if (Media.IsMuted)
- {
- Media.IsMuted = false;
- }
- if (Media.Volume < 1)
- {
- Media.Volume += .1;
- }
- }
- }
- }

Yuki YukiPosted Jan 5, 2018, 7:04 PM
You have playgrised, almost word for word copied from msdn article.
Santhakumar MunuswamyPosted Jun 24, 2015, 11:34 PM
Thanks for sharing