Storage file to System uri?

I have a Windows Metro app written in c#.

Here is the code I am using to pick a file from a 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 the System.Uri used to change the source of MediaElement. How do I make my file became a uri link? It seems that Uri("...") only accepts String of where the file location is.

Answers


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

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

Need Your Help

Set presence as unavailable - Facebook Chat API

ios facebook xmppframework facebook-chat user-presence

I'm using xmppframework to develop my xmpp client. I make a normal login in Facebook, after that i setup my xmppStream to connect my client with the facebook chat and then, I send the initial prese...

Is there any javascript libs for heatmaps which support Internet Explorer 8?

javascript jquery internet-explorer-8 heatmap vml

I am looking for some free javascript framework to implement nice heatmap chart. It should look something like D3 Heatmap. The problem is that it have to work in IE8 which do not support SVG. I goo...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.