Media(媒體)之音頻播放器, 視頻播放器, 與 Windows Phone 的音樂和視頻中心整合
介紹
與眾不同 windows phone 7.5 (sdk 7.1) 之媒體
音頻播放器
視頻播放器
與 Windows Phone 的音樂和視頻中心整合
樣本
1、示範音頻播放器
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="播放" Click="btnPlay_Click" /> <Button x:Name="btnPause" Content="暫停" Click="btnPause_Click" /> <TextBlock x:Name="lblStatus" /> </StackPanel> </Grid> </phone:PhoneApplicationPage>
Audio.xaml.cs
/* * MediaElement - 用於播放視頻或音頻,本地地址或遠程地址均可 * 支援的編碼格式參見:http://msdn.microsoft.com/en-us/library/ff462087(v=vs.92) * * MediaElement 的詳細說明參見:http://www.cnblogs.com/webabcd/archive/2008/12/01/1344632.html * Launcher 方式參見:http://www.cnblogs.com/webabcd/archive/2012/06/14/2548776.html 中的 MediaPlayerLauncher * * XNA 播放音頻參見: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) { // 顯示 MediaElement 的目前狀態 lblStatus.Text = mediaElement.CurrentState.ToString(); } private void btnPlay_Click(object sender, RoutedEventArgs e) { // 播放 mediaElement.Play(); } private void btnPause_Click(object sender, RoutedEventArgs e) { // 暫停 mediaElement.Pause(); } } }