首页 新闻 搜索 专区 学院

c# winform vlcplayer播放器导致程序崩溃

0
[待解决问题]
异常信息: System.AccessViolationException
   在 Vlc.DotNet.Core.Interops.VlcManager.SetMediaToMediaPlayer(Vlc.DotNet.Core.Interops.VlcMediaPlayerInstance, Vlc.DotNet.Core.Interops.VlcMediaInstance)
   在 Vlc.DotNet.Core.VlcMediaPlayer.SetMedia(Vlc.DotNet.Core.VlcMedia)
   在 Vlc.DotNet.Forms.VlcControl.Play(System.Uri, System.String[])
   在 KioskAPP.KioskForm+<>c__DisplayClass116_2.<CreateMP3>b__5()
   在 System.Threading.Tasks.Task.InnerInvoke()
   在 System.Threading.Tasks.Task.Execute()
   在 System.Threading.Tasks.Task.ExecutionContextCallback(System.Object)
   在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   在 System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
   在 System.Threading.Tasks.Task.ExecuteEntry(Boolean)
   在 System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   在 System.Threading.ThreadPoolWorkQueue.Dispatch()
   在 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

 

 

程序代码:

复制代码
        private void CreateMP3(string playUrl = "")
        {
            L.Info("CreateMP3 start");
            this.Invoke(new System.Action<object>(delegate {
                try
                {
                    if (pnlVlc.Controls.Count > 1){
              (pnlVlc.Controls[1] as VlcControl).Dispose();
            }
L.Info("CreateMP3:播放波普"); VlcControl vlcMP3 = new VlcPlayer().CreateVlc(); vlcMP3.EndReached += (ev, ek) => { Task.Run(() => { try { string videoPath = string.Format(localPath + "Music\\Shockwave{0}.mp4", 1); L.Info("MP3波普:"+videoPath); //循环播放 vlcMP3.Play(new Uri(videoPath)); } catch (Exception ex) { L.Error(string.Format("----MP3 Play Error:{0}----", ex.Message)); L.Error("----MP3 Play Error----", ex); } }); }; vlcMP3.Name = "vlcMP3"; vlcPlayer.Visible = false; pnlVlc.Controls.Add(vlcMP3); vlcMP3.Play(new Uri(localPath + "Music\\Shockwave1.mp4")); } catch (Exception ex) { L.Error(string.Format("----创建MP3异常:{0}", ex.Message)); } }), 1); }
复制代码
问题补充:

main里的全局异常捕获也没起作用

//处理UI线程异常
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            string str = GetExceptionMsg(e.Exception, e.ToString());
            L.Error(str);
        }
tommyhu的主页 tommyhu | 初学一级 | 园豆:117
提问于:2017-12-14 10:32
< >
分享
所有回答(3)
0

去掉Task.Run试试

dudu | 园豆:39028 (高人七级) | 2017-12-14 10:36

这个是偶尔出现,比较蛋疼

支持(0) 反对(0) tommyhu | 园豆:117 (初学一级) | 2017-12-14 10:42
0
try
                            {
                                var task = Task.Run(() => {
                                    string videoPath = string.Concat(localPath + "Music\\Shockwave1.mp4");
                                    vlcMP3.Play(new Uri(videoPath));
                                })
                                .ContinueWith((t) => 
                                {
                                    L.Error("----MP3 Play Error----", t.Exception);
                                },TaskContinuationOptions.OnlyOnFaulted);
                             }
                            catch (Exception ex)
                            {
                                L.Error("CreateMP3:播放波普{0}",ex);
                            }
tommyhu | 园豆:117 (初学一级) | 2017-12-14 15:03
0

 之前也写过vlc播放器,用C#写的,老是报内存溢出的问题,搞了好久终于好了

jqw2009 | 园豆:1946 (小虾三级) | 2018-01-09 15:55

请问是怎么修复的?我这也遇到了溢出的问题

支持(0) 反对(0) 帅帅的蓝莓 | 园豆:200 (初学一级) | 2018-12-27 13:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册