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.");
            }
        }
Beispiel #2
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.");
			}
		}