Storage file in System uri?

I have a Windows Metro application written in C #.

Here is the code that I use to select a file from the local music library:

FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary; openPicker.FileTypeFilter.Add(".mp3"); openPicker.FileTypeFilter.Add(".wav"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { myMediaElement.Source = file; //error here } else { //error here } 

It says that StorageFile cannot be converted to System.Uri , used to change the source of the MediaElement. How to make my file uri link? It seems that Uri("...") only accepts String where the file location is.

+7
source share
1 answer

You must use the file stream with SetSource . From How to play a local media file using MediaElement :

 var file = await openPicker.PickSingleFileAsync(); var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); myMediaElement.SetSource(stream, file.ContentType); 
+8
source

All Articles