2014-03-01 45 views
0

我正在嘗試做一些我認爲會非常簡單的事情,但它不能證明這一點。我想從我從API獲取的URI播放聲音剪輯。該URI爲音頻剪輯提供絕對URI。在Windows Phone 8中播放聲音剪輯

我試過使用MediaElement組件,它的工作原理,除了在剪輯下載/播放時掛起UI。這意味着糟糕的用戶體驗,並且可能無法通過商店認證。

我也嘗試過XNA框架中的SoundEffect類,但是它抱怨絕對URI - 看起來這隻適用於相對鏈接,因此不會足夠。

我不知道我有什麼其他選擇在了Windows Phone 8的應用程序,不會掛在UI

任何建議,歡迎播放聲音剪輯。

謝謝

回答

0

在網絡或互聯網上使用媒體文件將增加應用程序的延遲。在手機加載文件之前,您無法開始播放媒體。使用MediaElement.MediaOpened來確定媒體何時準備就緒,然後調用.Play();

當然,您需要讓用戶知道媒體正在下載。我的例子使用SystemTray ProgressIndicator向用戶顯示一條消息。

XAML

<Grid x:Name="ContentPanel" 
     Grid.Row="1" 
     Margin="12,0,12,0"> 
    <StackPanel> 
    <Button x:Name='PlayButton' 
      Click='PlayButton_Click' 
      Content='Play Media' /> 
    <MediaElement x:Name='media1' 
       MediaOpened='Media1_MediaOpened' 
       AutoPlay='False' /> 
    </StackPanel> 

</Grid> 

CODE

private void Media1_MediaOpened(object sender, RoutedEventArgs e) { 
    // MediaOpened event occurs when the media stream has been 
    // validated and opened, and the file headers have been read. 

    ShowProgressIndicator(false); 
    media1.Play(); 
} 

private void PlayButton_Click(object sender, RoutedEventArgs e) { 
    // the SystemTray has a ProgressIndicator 
    // that you can use to display progress during async operations. 
    SystemTray.ProgressIndicator = new ProgressIndicator(); 
    SystemTray.ProgressIndicator.Text = "Acquiring media - OverTheTop.mp3 "; 

    ShowProgressIndicator(true); 

    // Get the media 
    media1.Source = 
    new Uri(@"http://freesologuitar.com/mps/DonAlder_OverTheTop.mp3", 
       UriKind.Absolute); 
} 

private static void ShowProgressIndicator(bool isVisible) { 
    SystemTray.ProgressIndicator.IsIndeterminate = isVisible; 
    SystemTray.ProgressIndicator.IsVisible = isVisible; 
} 
+0

感謝。雖然這不能解決無響應的用戶界面(在下載示例時用戶界面仍處於鎖定狀態),但它確實提供了更好的用戶體驗 – LDJ

相關問題