When trying to set the URL in axWindowsMediaPlayer1 error: The Ссылка на объект не указывает на экземпляр объекта . The object itself really exists. The video player code is copied from another form, where everything works.

 public partial class Video : Slide { public AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1; public string bpath; public PictureBox video; public Video(string apath, string bpath) : base (apath) // apath - путь к фото из класса Slide, bpath - путь к видео { this.bpath = bpath; this.video = new System.Windows.Forms.PictureBox(); this.video.BackColor = System.Drawing.Color.Transparent; this.video.BackgroundImage = global::StPavel_TheForestSong.Properties.Resources.video2; this.video.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.video.Cursor = System.Windows.Forms.Cursors.Hand; this.video.Location = new System.Drawing.Point(387, 162); this.video.Name = "video"; this.video.Size = new System.Drawing.Size(70, 70); this.video.TabStop = false; this.video.Click += new System.EventHandler(video_Click); this.axWindowsMediaPlayer1 = new AxWMPLib.AxWindowsMediaPlayer(); this.axWindowsMediaPlayer1.Enabled = true; this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(79, 12); this.axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1"; ComponentResourceManager resources = new ComponentResourceManager(typeof(Video)); this.axWindowsMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWindowsMediaPlayer1.OcxState"))); this.axWindowsMediaPlayer1.Size = new System.Drawing.Size(430, 280); this.Controls.Add(this.video); this.Controls.Add(this.axWindowsMediaPlayer1); } private void video_Click(object sender, EventArgs e) { oneSlide(0); this.axWindowsMediaPlayer1.Visible = true; } public override void oneSlide(int i) // показывает одно видео { axWindowsMediaPlayer1.URL = "G:\\mf.mp4"; } } 
  • If you do not specify the URL, the player itself is shown on the form - Elena
  • If that was more succinctly just a NullReferenceException instead of a message, Ссылка на объект не указывает на экземпляр объекта . - Vadim Ovchinnikov
  • Have you tried to debug your version and work? - Vadim Ovchinnikov
  • @Vadim Ovchinnikov Debug in what sense? - Elena
  • Set a breakpoint and step by step. Do you understand me or need to explain in more detail? It is easy for me if that. - Vadim Ovchinnikov

1 answer 1

It seems to understand. The Video class is a Slide heir and the oneSlide method is overloaded in it. But this method is called during the initialization process of the parent Slide. Naturally, the original class does not accept the overloaded method.