我正在开发Windows手机应用程序,我必须通过网址运行视频。我尽了很多努力才能完成这项任务但却无法做到。 Example
媒体元素播放本地视频但不播放远程视频。
这是我的代码:
的Xaml:
<MediaElement Grid.Row="2" x:Name="player" AutoPlay="False"/>
我的cs代码:
private async void Play_This_Video(object sender, RoutedEventArgs e)
{
// video_url is string. I convert this to valid url
// I tried with direct passing string as player source.
// My Url looks like this "http://whatsappblog.in/Amazing-Dog-Diving-In-For-Rescue.mp4"
Uri url = new Uri(video_url);
player.Source = url;
}
我尝试使用xaml中的直接源,但视频无法播放。像
<MediaElement Grid.Row="2" x:Name="player" source"http://whatsappblog.in/Amazing-Dog-Diving-In-For-Rescue.mp4" AutoPlay="true"/>
我也试过了mp4网址。 “http://whatsappblog.in/Amazing-Dog-Diving-In-For-Rescue.mp4”
但在所有情况下,视频都无法播放。
然后我尝试使用此代码播放流
Uri url = new Uri(video_url);
var httpClient = new HttpClient();
var response = await httpClient.GetAsync(url);
var file = await response.Content.ReadAsByteArrayAsync();
MemoryStream ms = new MemoryStream(file);
var randomAccessStream = new MemoryRandomAccessStream(ms);
//There is an extra class to handle above function.
player.SetSource(randomAccessStream, "video/mp4");
player.play();
此代码未显示任何错误,但视频无法播放 你可以通过网址向我提供一个如何在媒体元素中运行视频文件的解决方案吗?