简体   繁体   English

C# program crashes when setting media player URL of axWindowsMediaPlayer object from separate form window: code 3221225477 0xc0000005 Access violation

[英]C# program crashes when setting media player URL of axWindowsMediaPlayer object from separate form window: code 3221225477 0xc0000005 Access violation

I'm making a C# Windows Forms program in Visual Studio which keeps crashing whenever I set the URL to a windows media player axWindowsMediaPLayer object. I'm making a C# Windows Forms program in Visual Studio which keeps crashing whenever I set the URL to a windows media player axWindowsMediaPLayer object.

There are two form windows: MainWindow and VideoForm. windows 有两种形式:MainWindow 和 VideoForm。 There are buttons on MainWindow to select a file via a fileDialog, and a button to open the VideoForm window which has the media player in it. MainWindow 上有通过 fileDialog 到 select 文件的按钮,以及打开包含媒体播放器的 VideoForm window 的按钮。 I created a custom Video.cs class to capture the video file information.我创建了一个自定义 Video.cs class 来捕获视频文件信息。 It also handles the fileDialog.它还处理文件对话框。 However, when I set the URL to the media player object, the program crashes with code 3221225477 (0xc0000005) 'Access violation' .但是,当我将 URL 设置为媒体播放器 object 时,程序崩溃,代码为 3221225477 (0xc0000005) 'Access violation' So, the URL of the media player in the VideoForm window is being set from the button click event in the MainWindow.因此,VideoForm window 中的媒体播放器的 URL 是从主窗口中的按钮单击事件设置的。 I'm not sure if this is what's causing the access violation.我不确定这是否是导致访问冲突的原因。 I have run Visual Studio as an administrator to ensure that it should have access to the file.我以管理员身份运行 Visual Studio 以确保它应该有权访问该文件。 I have checked the file path and it is correct.我检查了文件路径,它是正确的。 I've tried with and without the preceding @.我尝试过使用和不使用前面的@。

This is the line that causes the crash:这是导致崩溃的行:

VideoWindow.MediaPlayer.URL = @auditVideo.Path;

The relevant code is below:相关代码如下:

MainWindow.cs:主窗口.cs:

        Video auditVideo = new Video();
        private void ButtonImportVideo_Click(object sender, EventArgs e)
        {
            auditVideo.InitializeFile(openFileDialogVideo);

            textBoxVideoFile.Text = auditVideo.Name;
        }
        private void ButtonPlayVideo_Click(object sender, EventArgs e)
        {
            VideoForm VideoWindow = new VideoForm();
            try
            {
                VideoWindow.MediaPlayer.URL = @auditVideo.Path; // This is what causes the crash
            }
            catch(Exception ex)
            {
                MessageBox.Show("could not load the file" + ex.Message);
            }
            Console.WriteLine("VideoWindow.MediaPlayer.URL is {0}", @VideoWindow.MediaPlayer.URL);

            VideoWindow.Show();
        }

Video.cs class:视频.cs class:

namespace AVCAudit
{
    internal class Video
    {
        internal OpenFileDialog OpenFileDialog { get; private set; } //This is an AutoProperty which generates the private field behind the scenes
        internal string Path { get; private set; } //set should be private for Path and Name since they refer to the actual file on disk which doesn't change
        internal string Name { get; private set; }
        internal void InitializeFile(OpenFileDialog fileDialogArg)
        {
            OpenFileDialog = fileDialogArg;
            OpenFileDialog.InitialDirectory = @"C:\Users\schaney\Desktop\Neology\AVC Audit Project\avc_audit\Recordings";
            OpenFileDialog.Title = "Open audit video file";
            OpenFileDialog.Filter = "(mp3,wav,mp4,mov,wmv,mpg)|*.mp3;*.wav;*.mp4;*.mov;*.wmv;*.mpg|all files|*.*";
            if (OpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                Path = fileDialogArg.FileName;
                Name = fileDialogArg.SafeFileName;
            }
        }
    }
}

VideoForm.cs VideoForm.cs

namespace AVCAudit
{
    public partial class VideoForm : Form
    {
        internal String test { get; set; }
        public VideoForm() //constructor for VideoForm class. The rest of the partial class is defined in VideoForm.Designer.cs
        {
            InitializeComponent(); //so the constructor for this class just runs the InitializeComponent method defined in the Designer.cs file
        }
        private void MediaPlayer_Enter(object sender, EventArgs e)
        {

        }
    }
}

I have found the root cause of this crash which is the way these Dell laptops work with external graphics cards.我已经找到了这次崩溃的根本原因,这就是这些戴尔笔记本电脑与外部显卡一起工作的方式。 There is a specific arrangement where all graphics must be piped through the CPU's integrated graphics, even those which are processed through the external graphics card.有一种特殊的安排,即所有图形都必须通过 CPU 的集成图形进行管道传输,即使是通过外部图形卡处理的图形。 I have an nVidia Quadro card, but any application that wants to use it has to first go through the integrated graphics, then the CPU can determine whether or not it wants to use the Quadro for processing that request.我有一个 nVidia Quadro 卡,但是任何想要使用它的应用程序必须首先通过集成显卡 go,然后 CPU 可以确定是否要使用 Quadro 来处理该请求。 Basically from what I understand, applications should be blind to the Quadro, and do everything through the integrated graphics.基本上据我了解,应用程序应该对 Quadro 视而不见,并通过集成显卡完成所有工作。

For some reason, the C# axWindowsMediaPlayer object does not work properly with this arrangement and causes an access violation.出于某种原因,C# axWindowsMediaPlayer object 在这种安排下无法正常工作并导致访问冲突。 I would guess that it's trying to interact with the Quadro directly.我猜它试图直接与 Quadro 交互。

As a workaround, I can stop the crash by configuring nVidia Control Panel to use Integrated Graphics for the project's Debug and Release executable files.作为一种解决方法,我可以通过将 nVidia 控制面板配置为对项目的调试和发布可执行文件使用集成显卡来阻止崩溃。 This forces them to only interface with the integrated graphics, thus stopping the access violation.这迫使他们只与集成显卡接口,从而停止访问冲突。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 程序退出,代码为1073741819(0xc0000005)“访问冲突” - The program exited with code-1073741819 (0xc0000005) 'Access violation' C# 应用程序“已退出,代码为 -1073741819 (0xc0000005)‘访问冲突’”VS - C# app "has exited with code -1073741819 (0xc0000005) 'Access violation'" VS 从C#调用非托管C ++库(dll)会产生访问冲突错误(0xc0000005) - Calling unmanaged C++ library (dll) from C# creates an access violation error (0xc0000005) 访问冲突错误崩溃程序(0xc0000005) - Access Violation error crashing program (0xc0000005) 当我尝试启动程序时:(0xc0000005) '访问冲突' 错误 - When i'm trying to start the program: (0xc0000005) 'Access violation' error 尝试从 memory 位置 0x00000000 读取时访问冲突异常 (0xC0000005) - Access violation exception (0xC0000005) when trying to read from memory location 0x00000000 使用异常代码从窗口服务获取错误:0xc0000005 - Getting error from window service with Exception code: 0xc0000005 iisexpress 崩溃由客户端 web 浏览器触发。 错误是“程序 iisexpress exe 已退出,代码为 0xc0000005 访问冲突” - iisexpress crash triggered by the client web browser. The error is "the program iisexpress exe has exited with code 0xc0000005 access violation" Outlook 异常代码:0xc0000005 Visual Studio C# - Outlook Exception code : 0xc0000005 Visual studio C# 0xC0000005:访问冲突读取位置0xffffffffffffffffff - 0xC0000005: Access violation reading location 0xffffffffffffffff
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM