I wanna playback some audiofiles in a UniversalWindowsApp
to those I've only got the path. This is my current code:
//exception in this line:
var file = await StorageFile.GetFileFromPathAsync(@"C:\Users\myuser\Music\someartist\album\01. Title.mp3");
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
mediaControl.SetSource(stream, file.ContentType);
mediaControl.Play();
I also tried this code snippet:
mediaControl.Source = new Uri(@"C:\Users\myuser\Music\someartist\album\01. Title.mp3", UriKind.RelativeOrAbsolute);
But both codes throw an exception as follows:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Which is not really located at the first one (means that it then immediately jumps to the UnhandledException
), as it breaks to the middle line (copied from App.g.i.cs
/InitializeComponent()
):
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
If I use the sample code from msdn it works:
async private void SetLocalMedia()
{
var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
openPicker.FileTypeFilter.Add(".mp3");
var file = await openPicker.PickSingleFileAsync();
// mediaControl is a MediaElement defined in XAML
if (null != file)
{
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
mediaControl.SetSource(stream, file.ContentType);
mediaControl.Play();
}
}
Which does obviously the same as mine expect the FileOpenPicker
- a dialog I won't show up as I already have the filepath.
The question is, how can I playback some audio in a UniversalWindowsApp
?
Thanks in advance!