我在这里粘贴代码。我的应用程序能够访问音乐库。我没有收到任何异常,但导航后没有播放媒体文件。这是 Skydrive 上托管的项目
主页.xaml
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button Content="Click Me" Margin="563,357,0,373" Click="Button_Click_1"></Button>
</Grid>
MainPage.xaml.cs
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
StorageFile file = await KnownFolders.MusicLibrary.GetFileAsync("video.mp4");
Frame.Navigate(typeof(MediaPlayback), file);
}
媒体播放.xaml
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<MediaElement x:Name="MyMediaPlayback" Height="350" Width="640"/>
</Grid>
媒体播放.xaml.cs
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
StorageFile file = e.Parameter as StorageFile;
try
{
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
MyMediaPlayback.SetSource(stream, file.ContentType);
MyMediaPlayback.Play();
}
catch (Exception)
{
throw;
}
}