Quantcast
Viewing all articles
Browse latest Browse all 12583

Memory Leaks in windows media player ActiveX control?

There is a memory leak bug in my winform application.

In order to find out the cause, I maked a simple test application to build the bug. The application has only one Form, the Form has a Button and a windows media player ActiveX control named "axWindowsMediaPlayer1". Parts of the codes is shown below:

private void Form1_Load(object sender, EventArgs e) { this.axWindowsMediaPlayer1.uiMode = "none"; this.axWindowsMediaPlayer1.settings.mute = true; this.axWindowsMediaPlayer1.settings.autoStart = false; this.axWindowsMediaPlayer1.enableContextMenu = false; this.axWindowsMediaPlayer1.windowlessVideo = true; this.axWindowsMediaPlayer1.fullScreen = false; this.axWindowsMediaPlayer1.settings.setMode("loop", true); }

private bool m_bLoopFlag = false; private void btnLoop_Click(object sender, EventArgs e) { m_bLoopFlag = true; Thread thd = new Thread(new ThreadStart(this.LoopPlayThread)); thd.IsBackground = true; thd.Start(); } private void LoopPlayThread() { string strUrl = ""; for (int i = 0; i < 50000; i++) { strUrl = @"http://192.168.1.101/video/a.mp4"; this.Invoke(new MethodInvoker(delegate { PlayUrl(strUrl, true); })); if (!m_bLoopFlag) return; Thread.Sleep(3000); strUrl = @"http://192.168.1.101/video/b.mp4"; this.Invoke(new MethodInvoker(delegate { PlayUrl(strUrl, false); })); if (!m_bLoopFlag) return; } } private void PlayUrl(string url, bool startPlay) { IWMPMedia media = axWindowsMediaPlayer1.newMedia(url); if (axWindowsMediaPlayer1.currentMedia != null && !axWindowsMediaPlayer1.currentMedia.get_isIdentical(media)) { axWindowsMediaPlayer1.Ctlcontrols.stop(); axWindowsMediaPlayer1.currentPlaylist.clear(); } axWindowsMediaPlayer1.currentMedia = media; if (startPlay) { axWindowsMediaPlayer1.Ctlcontrols.play(); } }

I have found some key points to build the problem.

1. The media played by wmp must be a net mp4 media, in my test application, it's placed in a IIS virtual directory.
2. The size of the mp4 file is large enough(>300MB ?).

My machine's system info: 

OS 32Bit Windows 7 Ultimate with SP1
Processor Intel(R) Core(TM) i5 CPU         750  @ 2.67GHz, 2668 Mhz, 4 Core(s), 4 Logical Processor(s)
Total Physical Memory 2.96 GB
Display  NVIDIA GeForce 205    Driver Version 9.18.13.697

May anyone tell me what's the problem of my code, or any suggestions?
Best regards



Viewing all articles
Browse latest Browse all 12583

Trending Articles