PDA

View Full Version : سوال: باگ در توقف پخش فایل ویدیوی با ActiveMovie COM component ‎



bmyazdani
چهارشنبه 31 تیر 1388, 11:46 صبح
سلام
با استفاده از ActiveMovie COM component یک Media Player دارم. .فایل های صوتی و تصویری به خوبی پخش می شوند، تنها یک باگ وجود داره : اگر حین پخش یک فایل ویدیویی یک فایل صوتی رو انتخاب کنم. آخرین فریم از ویدویی که در حال پخش بود در picturebox باقی می مونه..
چطوری باید پاکش کنم؟؟؟
از

pictureBox1.Image = null;هم استفاده کردم ولی بی فایده بود

http://xs.to/xs.php?h=xs941&d=09303&f=player848.jpghttp://xs941.xs.to/xs941/09303/player848.jpg

کد برنامه:





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuartzTypeLib;

namespace Playvedio
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}
// Define constants used for specifying the window style.
private const int WS_CHILD = 0x40000000;
private const int WS_CLIPCHILDREN = 0x2000000;

// Hold a form-level reference to the media control interface,
// so the code can control playback of the currently loaded
// movie.
//private IMediaControl mc = null;
private QuartzTypeLib.FilgraphManagerClass mediacontrol = null;
QuartzTypeLib.FilgraphManagerClass graphManager = new QuartzTypeLib.FilgraphManagerClass();


// Hold a form-level reference to the video window in case it
// needs to be resized.
private IVideoWindow videoWindow = null;
private void browse_Click(object sender, EventArgs e)
{
// Allow the user to choose a file.
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter =
"Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3;*. wmv|" +
"All Files|*.*";

//mediacontrol = (QuartzTypeLib.FilgraphManagerClass)graphManager;
if (DialogResult.OK == openFileDialog.ShowDialog())
{
// Stop the playback for the current movie, if it exists.
if (mediacontrol != null)
{
mediacontrol.Stop();
mediacontrol.CurrentPosition = 0;
pictureBox1.Image = null;

}

//// Load the movie file.
//FilgraphManager graphManager = new FilgraphManager();
////graphManager.RenderFile(openFileDialog.FileName);
//textBox1.Text = (openFileDialog.FileName);
//graphManager.RenderFile(openFileDialog.FileName);

QuartzTypeLib.FilgraphManagerClass graphManager = new QuartzTypeLib.FilgraphManagerClass();
////graphManager.RenderFile(openFileDialog.FileName);
////textBox1.Text = (openFileDialog.FileName);
////graphManager.CurrentPosition = 0;
mediacontrol = (QuartzTypeLib.FilgraphManagerClass)graphManager;
mediacontrol.RenderFile(openFileDialog.FileName);
textBox1.Text = (openFileDialog.FileName);
mediacontrol.CurrentPosition = 0;



// Attach the view to a picture box on the form.
try
{
videoWindow = (IVideoWindow)graphManager;
videoWindow.Owner = (int)pictureBox1.Handle;
videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
videoWindow.SetWindowPosition(
pictureBox1.ClientRectangle.Left,
pictureBox1.ClientRectangle.Top,
pictureBox1.ClientRectangle.Width,
pictureBox1.ClientRectangle.Height);
}
catch
{
// An error can occur if the file does not have a video
// source (for example, an MP3 file.)
// You can ignore this error and still allow playback to
// continue (without any visualization).
}
}
}
private void stop_Click(object sender, EventArgs e)
{
if(mediacontrol != null)
{
mediacontrol.Stop();
mediacontrol.CurrentPosition = 0;
pictureBox1.Image = null;
}


//pictureBox1.Visible =false;

}
private void pictureBox1_SizeChanged(object sender, EventArgs e)
{
if (videoWindow != null)
{
try
{
videoWindow.SetWindowPosition(
pictureBox1.ClientRectangle.Left,
pictureBox1.ClientRectangle.Top,
pictureBox1.ClientRectangle.Width,
pictureBox1.ClientRectangle.Height);
}
catch
{
// Ignore the exception thrown when resizing the form
// when the file does not have a video source.
}
}
}

private void Play_Click(object sender, EventArgs e)
{
pictureBox1.Visible = true;
if(mediacontrol != null)
{
mediacontrol.CurrentPosition = 0;
mediacontrol.Run();
}
}



}
}

فایل اجرایی: