[Windows Phone 8]媒體播放器之應用
前言
-------------------------------------------------------------------------------
當我們在做應用程式時,有時會想要撥放影片讓使用者觀看,
卻不知道如何製作嗎?很簡單,今天要教大家如何呼叫
內部的媒體播放器喔!
背景知識
-------------------------------------------------------------------------------
這次運用到的是 MediaPlayerLauncher 啟動器
這個啟動器常用的屬性有
Controls 屬性 : 啟動媒體播放器的控制元件,如"暫停"、"停止"
Location 屬性 : 指定媒體存放的位置
Media 屬性 : 要播放媒體的URI
Orientation : 播放器的顯示方向
實做
---------------------------------------------------------------------------------
1.建立一個新的專案
2.在MainPage.xaml上建立一個Button按鈕
 <!--LayoutRoot 是放置所有頁面的根資料格-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>      
        <!--TitlePanel 包含應用程式的名稱和頁面標題-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="我的應用程式" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
            <TextBlock Text="媒體播放器" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>
        <!--ContentPanel - 其他內容置於此-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="播放多媒體" VerticalAlignment="Top" Click="playclick" />
        </Grid>
    </Grid>
3.我們再到MainPage.xaml.cs編寫Click事件
首先我們先
using Microsoft.Phone.Tasks;
然後在編寫程式碼
 private void playclick(object sender, RoutedEventArgs e)
        {
            //建構啟動器對象
            MediaPlayerLauncher MyMediaPlayer = new MediaPlayerLauncher();
            //媒體檔案來源為應用程式安裝目錄
            MyMediaPlayer.Location = MediaLocationType.Install;
            //顯示"暫停"和"停止"兩個按鈕
            MyMediaPlayer.Controls = MediaPlaybackControls.Pause | MediaPlaybackControls.Stop;
            //媒體播放器縱向顯示
            MyMediaPlayer.Orientation = MediaPlayerOrientation.Portrait;
            //設定要播放的媒體
            MyMediaPlayer.Media = new Uri("DancingQueen.mp3", UriKind.Relative);
            //顯示播放器
            MyMediaPlayer.Show();
        }
4.別忘了把媒體加到方案總管理喔!
5.接著我們來測試看看吧
結語
--------------------------------------------------------------------------------------------------------
是不是很簡單呢!動手做做看吧 ^_^
希望對大家有幫助^_^
如果上述有錯誤,請不吝指教喔! 感謝大家
參考資料
--------------------------------------------------------------------------------------------------------
MediaPlayerLauncher Class – Windows Phone Dev Center
	How to use the Media Player launcher for Windows Phone
	– Windows Phone Dev Center