Reputation: 146
I have web Uri like: http://123.456.769/music.mp4.
While I set MediaElement's Source with that uri, I got a media failed exception ("Could not open that video"),
But I can play this file, if download and rename it to "music.mp3";
How can play it without download?
Upvotes: 0
Views: 791
Reputation: 5575
Create a Stream via the Uri. You can use the RandomAccessStreamReference
class.
var uriStreamReference = RandomAccessStreamReference.CreateFromUri(myUri);
var uriStream = await uriStreamReference.OpenAsync();
You can then set the source of your MediaElement
via the SetSource
method. You can also set the MIME type for mp4 audio.
myMediaElement.SetSource(uriStream, "audio/mp4");
If it's an mp3 whose filename is simply an mp4, switch to audio/mpeg
.
Hope this helps and happy coding!
Upvotes: 1