使用MediaPlayer打开https协议失败的在线视频 [英] Use MediaPlayer to open an online video of https protocol failed
问题描述
可以成功打开"http"。视频,但是"https"失败。
代码:
MediaPlayer player = new MediaPlayer();
播放器。 Open(new Uri(@"https://www.musictime-studio.com/webfile/musical_demo/20180730045604.mp3" ;, UriKind.Absolute));
exception:System。 NullReferenceException;
任何可以帮助我的人!!
你好bp_l,
从下面的帖子看,它似乎是WPF中的问题,作为一种解决方法,我建议您可以将视频下载到本地路径然后打开它,以下代码供您参考。
public Window1()
{
InitializeComponent();
MediaPlayer player = new MediaPlayer();
var source = new Uri(@" https://www.musictime-studio.com/webfile/musical_demo/20180730045604.mp3" ;,UriKind.Absolute);
byte [] video = GetByteFromUrl(@" https://www.musictime-studio.com/webfile/musical_demo/20180730045604.mp3");
System.IO.File.WriteAllBytes(" temp1.mp3",video);
player.Open(new Uri(" temp1.mp3",UriKind.Relative));
VideoDrawing drawing = new VideoDrawing();
drawing.Rect = new Rect(0,0,300,200);
drawing.Player = player;
player.Play();
DrawingBrush brush = new DrawingBrush(drawing);
this.Background = brush;
}
private byte [] GetByteFromUrl(string url)
{
byte [] videoData = null;
使用(var wc = new System.Net.WebClient())
videoData = wc.DownloadData(url);
返回videoData;
}
祝你好运,
章龙
it can be successed to open a "http" video,but "https" is failed.
code:
MediaPlayer player=new MediaPlayer();
player.Open(new Uri(@"https://www.musictime-studio.com/webfile/musical_demo/20180730045604.mp3", UriKind.Absolute));
exception:System.NullReferenceException;
anyone who can help me!!
Hi bp_l,
From the following thread, it seems that it is know issue in WPF, As a workaround, I would suggest that you could download the video to the local path then open it, the following code for your reference.
public Window1() { InitializeComponent(); MediaPlayer player = new MediaPlayer(); var source = new Uri(@"https://www.musictime-studio.com/webfile/musical_demo/20180730045604.mp3", UriKind.Absolute); byte[] video = GetByteFromUrl(@"https://www.musictime-studio.com/webfile/musical_demo/20180730045604.mp3"); System.IO.File.WriteAllBytes("temp1.mp3", video); player.Open(new Uri("temp1.mp3", UriKind.Relative)); VideoDrawing drawing = new VideoDrawing(); drawing.Rect = new Rect(0, 0, 300, 200); drawing.Player = player; player.Play(); DrawingBrush brush = new DrawingBrush(drawing); this.Background = brush; } private byte[] GetByteFromUrl(string url) { byte[] videoData = null; using (var wc = new System.Net.WebClient()) videoData = wc.DownloadData(url); return videoData; }Best regards,
Zhanglong
这篇关于使用MediaPlayer打开https协议失败的在线视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!