Пример #1
0
    /**********************************************************
     * 摘要:此方法收集要显示的 AVI 的文件名,
     * 然后创建 Quartz COM 对象的实例。
     * 为了显示 AVI,程序对
     * IMediaControl 调用 RenderFile 和 Run。Quartz 使用自己的线程和窗口来显示
     * AVI。主线程阻塞在 ReadLine 上,直到用户按
     * Enter 键为止。
     *      输入参数:要显示的 avi 文件的位置
     *      返回值:void
     *************************************************************/

    public static void Main(string[] args)
    {
        // 检查用户是否传入了文件名:
        if (args.Length != 1)
        {
            DisplayUsage();

            return;
        }

        if (args[0] == "/?")
        {
            DisplayUsage();
            return;
        }

        String filename = args[0];

        // 检查文件是否存在
        if (!System.IO.File.Exists(filename))
        {
            Console.WriteLine("File " + filename + " not found.");
            DisplayUsage();
            return;
        }

        // 创建 Quartz 的实例
        // (Calls CoCreateInstance(E436EBB3-524F-11CE-9F53-0020AF0BA770,
        //  NULL, CLSCTX_ALL, IID_IUnknown,
        //  &graphManager).):
        try
        {
            QuartzTypeLib.FilgraphManager graphManager =
                new QuartzTypeLib.FilgraphManager();

            // IMediaControl 接口的 QueryInterface:
            QuartzTypeLib.IMediaControl mc =
                (QuartzTypeLib.IMediaControl)graphManager;

            // 对 COM 接口调用某些方法。
            // 将文件传递给 COM 对象上的 RenderFile 方法。
            mc.RenderFile(filename);

            // 显示文件。
            mc.Run();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Unexpected COM exception: " + ex.Message);
        }
        // 等待完成。
        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
Пример #2
0
    /************************************************************
     * Аннотация. Этот метод находит имя AVI-файла для воспроизведения,
     * а затем создает экземпляр COM-объекта Quartz.
     * Чтобы воспроизвести AVI-файл, программа вызывает методы RenderFile и Run из
     * IMediaControl. Quartz использует свои собственные поток и окно для воспроизведения
     * AVI-файла. Главный поток заблокирован на ReadLine до тех пор, пока пользователь не нажмет клавишу
     * ВВОД.
     *      Входные параметры: место размещения avi-файла, предназначенного для воспроизведения
     *      Возвращает: void
     **************************************************************/

    public static void Main(string[] args)
    {
        // Проверка передачи  пользователем имени файла:
        if (args.Length != 1)
        {
            DisplayUsage();

            return;
        }

        if (args[0] == "/?")
        {
            DisplayUsage();
            return;
        }

        String filename = args[0];

        // Проверка наличия файла
        if (!System.IO.File.Exists(filename))
        {
            Console.WriteLine("File " + filename + " not found.");
            DisplayUsage();
            return;
        }

        // Создание экземпляра Quartz
        // (Calls CoCreateInstance(E436EBB3-524F-11CE-9F53-0020AF0BA770,
        //  NULL, CLSCTX_ALL, IID_IUnknown,
        //  &graphManager).):
        try
        {
            QuartzTypeLib.FilgraphManager graphManager =
                new QuartzTypeLib.FilgraphManager();

            // QueryInterface для интерфейса IMediaControl:
            QuartzTypeLib.IMediaControl mc =
                (QuartzTypeLib.IMediaControl)graphManager;

            // Вызов некоторых методов COM-интерфейса
            // Передача файла в метод RenderFile COM-объекта.
            mc.RenderFile(filename);

            // Показать файл.
            mc.Run();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Unexpected COM exception: " + ex.Message);
        }
        // Дождитесь завершения.
        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
Пример #3
0
    /**********************************************************
     * Abstract: This method collects the filename of an AVI to show
     * then creates an instance of the Quartz COM object.
     * To show the AVI, the program calls RenderFile and Run on
     * IMediaControl. Quartz uses its own thread and window to
     * display the AVI. The main thread blocks on a ReadLine until
     * the user presses ENTER.
     *      Input Parameters: the location of the avi file it is going to display
     *      Returns: void
     *************************************************************/

    public static void Main(string[] args)
    {
        // Check to see if the user passed in a filename:
        if (args.Length != 1)
        {
            DisplayUsage();

            return;
        }

        if (args[0] == "/?")
        {
            DisplayUsage();
            return;
        }

        String filename = args[0];

        // Check to see if the file exists
        if (!System.IO.File.Exists(filename))
        {
            Console.WriteLine("File " + filename + " not found.");
            DisplayUsage();
            return;
        }

        // Create instance of Quartz
        // (Calls CoCreateInstance(E436EBB3-524F-11CE-9F53-0020AF0BA770,
        //  NULL, CLSCTX_ALL, IID_IUnknown,
        //  &graphManager).):
        try
        {
            QuartzTypeLib.FilgraphManager graphManager =
                new QuartzTypeLib.FilgraphManager();

            // QueryInterface for the IMediaControl interface:
            QuartzTypeLib.IMediaControl mc =
                (QuartzTypeLib.IMediaControl)graphManager;

            // Call some methods on a COM interface.
            // Pass in file to RenderFile method on COM object.
            mc.RenderFile(filename);

            // Show file.
            mc.Run();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Unexpected COM exception: " + ex.Message);
        }
        // Wait for completion.
        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
        private void cmdPlay_Click(object sender, EventArgs e)
        {
            if (mc == null)
            {
                // This audio is being played for the first time.
                // Load the file.

                // Access the IMediaControl interface.
                graphManager = new QuartzTypeLib.FilgraphManager();
                mc           = (QuartzTypeLib.IMediaControl)graphManager;
                audio        = (QuartzTypeLib.IBasicAudio)graphManager;
                position     = (QuartzTypeLib.IMediaPosition)graphManager;
                mEventEx     = (QuartzTypeLib.IMediaEventEx)graphManager;

                try
                {
                    // Choose a file.
                    mc.RenderFile(Application.StartupPath + "\\test.mp3");
                    mEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);
                }
                catch (FileNotFoundException err)
                {
                    MessageBox.Show("File not found.");
                    return;
                }
                catch (COMException err)
                {
                    MessageBox.Show("COM error.");
                    return;
                }
            }

            // Start playing the audio asynchronously.
            try
            {
                statusLabel1.Text = "Total: " +
                                    ConvertTimeToString((int)position.Duration);

                mc.Run();
                timer1.Start();
            }
            catch (COMException err)
            {
                MessageBox.Show("COM error.");
            }
        }
Пример #5
0
		private void cmdPlay_Click(object sender, EventArgs e)
		{
			if (mc == null)
			{
				// This audio is being played for the first time.
				// Load the file.

				// Access the IMediaControl interface.
				graphManager = new QuartzTypeLib.FilgraphManager();
				mc = (QuartzTypeLib.IMediaControl)graphManager;
				audio = (QuartzTypeLib.IBasicAudio)graphManager;
				position = (QuartzTypeLib.IMediaPosition)graphManager;
				mEventEx = (QuartzTypeLib.IMediaEventEx)graphManager;

				try
				{
					// Choose a file.
					mc.RenderFile(Application.StartupPath + "\\test.mp3");
					mEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);			
				}
				catch (FileNotFoundException err)
				{
					MessageBox.Show("File not found.");
					return;
				}
				catch (COMException err)
				{
					MessageBox.Show("COM error.");
					return;
				}
			}

			// Start playing the audio asynchronously.
			try
			{
				statusLabel1.Text = "Total: " +
					ConvertTimeToString((int)position.Duration);

				mc.Run();
				timer1.Start();			
			}
			catch (COMException err)
			{
				MessageBox.Show("COM error.");
			}
		}
Пример #6
0
        private void _play(bool start)
        {
            mc.RenderFile(_filename);
            try
            {
                int n = wm.WindowStyle;
                if (n == 0)
                {
                }
                bIsVideo = true;
            }
            catch
            {
                bIsVideo = false;
            }
            if (bIsVideo)
            {
                if (ctrlOwner != null)
                {
                    wm.WindowStyle = 0;
                    if (UseVideoPosition)
                    {
                        wm.Left = VideoPosition.X;
                        wm.Top  = VideoPosition.Y;
                    }
                    else
                    {
                        switch (VideoAllign)
                        {
                        case System.Drawing.ContentAlignment.MiddleCenter:
                            if (ctrlOwner.ClientSize.Width > wm.Width)
                            {
                                wm.Left = (ctrlOwner.ClientSize.Width - wm.Width) / 2;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            if (ctrlOwner.ClientSize.Height > wm.Height)
                            {
                                wm.Top = (ctrlOwner.ClientSize.Height - wm.Height) / 2;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.BottomCenter:
                            if (ctrlOwner.ClientSize.Width > wm.Width)
                            {
                                wm.Left = (ctrlOwner.ClientSize.Width - wm.Width) / 2;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            if (ctrlOwner.ClientSize.Height > wm.Height)
                            {
                                wm.Top = ctrlOwner.ClientSize.Height - wm.Height;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.BottomLeft:
                            wm.Left = 0;
                            if (ctrlOwner.ClientSize.Height > wm.Height)
                            {
                                wm.Top = ctrlOwner.ClientSize.Height - wm.Height;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.BottomRight:
                            if (ctrlOwner.ClientSize.Width > wm.Width)
                            {
                                wm.Left = ctrlOwner.ClientSize.Width - wm.Width;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            if (ctrlOwner.ClientSize.Height > wm.Height)
                            {
                                wm.Top = ctrlOwner.ClientSize.Height - wm.Height;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.MiddleLeft:
                            wm.Left = 0;
                            if (ctrlOwner.ClientSize.Height > wm.Height)
                            {
                                wm.Top = (ctrlOwner.ClientSize.Height - wm.Height) / 2;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.MiddleRight:
                            if (ctrlOwner.ClientSize.Width > wm.Width)
                            {
                                wm.Left = ctrlOwner.ClientSize.Width - wm.Width;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            if (ctrlOwner.ClientSize.Height > wm.Height)
                            {
                                wm.Top = (ctrlOwner.ClientSize.Height - wm.Height) / 2;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.TopCenter:
                            if (ctrlOwner.ClientSize.Width > wm.Width)
                            {
                                wm.Left = (ctrlOwner.ClientSize.Width - wm.Width) / 2;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            wm.Top = 0;
                            break;

                        case System.Drawing.ContentAlignment.TopLeft:
                            wm.Left = 0;
                            wm.Top  = 0;
                            break;

                        case System.Drawing.ContentAlignment.TopRight:
                            if (ctrlOwner.ClientSize.Width > wm.Width)
                            {
                                wm.Left = ctrlOwner.ClientSize.Width - wm.Width;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            wm.Top = 0;
                            break;
                        }
                    }
                    wm.Owner        = (int)ctrlOwner.Handle;
                    wm.MessageDrain = (int)ctrlOwner.Handle;
                }
                else
                {
                    if (UseVideoPosition)
                    {
                        wm.Left = VideoPosition.X;
                        wm.Top  = VideoPosition.Y;
                    }
                    else
                    {
                        System.Windows.Forms.Screen sr = System.Windows.Forms.Screen.PrimaryScreen;
                        switch (VideoAllign)
                        {
                        case System.Drawing.ContentAlignment.MiddleCenter:
                            if (sr.Bounds.Width > wm.Width)
                            {
                                wm.Left = (sr.Bounds.Width - wm.Width) / 2;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            if (sr.Bounds.Height > wm.Height)
                            {
                                wm.Top = (sr.Bounds.Height - wm.Height) / 2;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.BottomCenter:
                            if (sr.Bounds.Width > wm.Width)
                            {
                                wm.Left = (sr.Bounds.Width - wm.Width) / 2;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            if (sr.Bounds.Height > wm.Height)
                            {
                                wm.Top = sr.Bounds.Height - wm.Height;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.BottomLeft:
                            wm.Left = 0;
                            if (sr.Bounds.Height > wm.Height)
                            {
                                wm.Top = sr.Bounds.Height - wm.Height;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.BottomRight:
                            if (sr.Bounds.Width > wm.Width)
                            {
                                wm.Left = sr.Bounds.Width - wm.Width;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            if (sr.Bounds.Height > wm.Height)
                            {
                                wm.Top = sr.Bounds.Height - wm.Height;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.MiddleLeft:
                            wm.Left = 0;
                            if (sr.Bounds.Height > wm.Height)
                            {
                                wm.Top = (sr.Bounds.Height - wm.Height) / 2;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.MiddleRight:
                            if (sr.Bounds.Width > wm.Width)
                            {
                                wm.Left = sr.Bounds.Width - wm.Width;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            if (sr.Bounds.Height > wm.Height)
                            {
                                wm.Top = (sr.Bounds.Height - wm.Height) / 2;
                            }
                            else
                            {
                                wm.Top = 0;
                            }
                            break;

                        case System.Drawing.ContentAlignment.TopCenter:
                            if (sr.Bounds.Width > wm.Width)
                            {
                                wm.Left = (sr.Bounds.Width - wm.Width) / 2;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            wm.Top = 0;
                            break;

                        case System.Drawing.ContentAlignment.TopLeft:
                            wm.Left = 0;
                            wm.Top  = 0;
                            break;

                        case System.Drawing.ContentAlignment.TopRight:
                            if (sr.Bounds.Width > wm.Width)
                            {
                                wm.Left = sr.Bounds.Width - wm.Width;
                            }
                            else
                            {
                                wm.Left = 0;
                            }
                            wm.Top = 0;
                            break;
                        }
                    }
                    wm.Owner = 0;
                }
                if (UseManualSize)
                {
                    wm.Width  = ManualSize.Width;
                    wm.Height = ManualSize.Height;
                }
            }
            bLoaded = true;
            if (AutoPlay || start)
            {
                Play();
            }
            else
            {
                mc.Run();
                mc.Pause();
                mp.CurrentPosition = 0;
            }
        }