使用MediaPlayer打开https协议失败的在线视频 [英] Use MediaPlayer to open an online video of https protocol failed

查看:181
本文介绍了使用MediaPlayer打开https协议失败的在线视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以成功打开"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;
}


https://stackoverflow.com/questions/25081956/how-to- make-a-wpf-mediaelement-play-when-source-is-a-https-uri


祝你好运,


章龙


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;
        }

https://stackoverflow.com/questions/25081956/how-to-make-a-wpf-mediaelement-play-when-its-source-is-a-https-uri

Best regards,

Zhanglong


这篇关于使用MediaPlayer打开https协议失败的在线视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆