Media Audio player, video player, integrated with Windows Phone's music and video Center
Introduced
Special media for Windows Phone 7.5 (SDK 7.1)
Audio player
Video player
Integration with Windows Phone's music and video Center
Example
1. Demo Audio player
Audio.xaml
<phone: PhoneApplicationPage
x: Class = "Demo.Media.Audio"
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns: phone = "clr-namespace: Microsoft.Phone.Controls; assembly = Microsoft.Phone"
xmlns: shell = "clr-namespace: Microsoft.Phone.Shell; assembly = Microsoft.Phone"
xmlns: d = "http://schemas.microsoft.com/expression/blend/2008"
xmlns: mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily = "{StaticResource PhoneFontFamilyNormal}"
FontSize = "{StaticResource PhoneFontSizeNormal}"
Foreground = "{StaticResource PhoneForegroundBrush}"
SupportedOrientations = "Portrait" Orientation = "Portrait"
mc: Ignorable = "d" d: DesignHeight = "768" d: DesignWidth = "480"
shell: SystemTray.IsVisible = "True">
<Grid x: Name = "LayoutRoot" Background = "Transparent">
<StackPanel Orientation = "Vertical">
<MediaElement x: Name = "mediaElement" Source = "Assets / SuperMario.mp3" AutoPlay = "False" />
<Button x: Name = "btnPlay" Content = "Play" Click = "btnPlay_Click" />
<Button x: Name = "btnPause" Content = "Pause" Click = "btnPause_Click" />
<TextBlock x: Name = "lblStatus" />
</ StackPanel>
</ Grid>
</ phone: PhoneApplicationPage>
Audio.xaml.cs
/ *
* MediaElement-for playing video or audio, either local address or remote address
* Refer to: http://msdn.microsoft.com/en-us/library/ff462087(v=vs.92) for the supported encoding formats
*
* For detailed description of MediaElement, please see: http://www.cnblogs.com/webabcd/archive/2008/12/01/1344632.html
* For the launcher method, please refer to: MediaPlayerLauncher in http://www.cnblogs.com/webabcd/archive/2012/06/14/2548776.html
*
* XNA playback audio see: http://www.cnblogs.com/webabcd/archive/2011/07/11/2102713.html
* /
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace Demo.Media
{
public partial class Audio: PhoneApplicationPage
{
public Audio ()
{
InitializeComponent ();
mediaElement.CurrentStateChanged + = new RoutedEventHandler (mediaElement_CurrentStateChanged);
}
void mediaElement_CurrentStateChanged (object sender, RoutedEventArgs e)
{
// Display the current state of MediaElement
lblStatus.Text = mediaElement.CurrentState.ToString ();
}
private void btnPlay_Click (object sender, RoutedEventArgs e)
{
// play
mediaElement.Play ();
}
private void btnPause_Click (object sender, RoutedEventArgs e)
{
// time out
mediaElement.Pause ();
}
}
}