Section 17.13. Windows Media Player


17.13. Windows Media Player

The Windows Media Player control enables an application to play video and sound in many multimedia formats. These include MPEG (Motion Pictures Experts Group) audio and video, AVI (audio-video interleave) video, WAV (Windows wave-file format) audio and MIDI (Musical Instrument Digital Interface) audio. Users can find pre-existing audio and video on the Internet, or they can create their own files, using available sound and graphics packages.

The application in Fig. 17.27 demonstrates the Windows Media Player control. To use this control, you must add the control to the Toolbox. First select Tools > Choose Toolbox Items... to display the Choose Toolbox Items dialog. Click the COM components tab, then scroll down and select the option Windows Media Player. Click the OK button to dismiss the dialog. The Windows Media Player control now appears at the bottom of the Toolbox.

Figure 17.27. Windows Media Player demonstration.

  1  ' Fig. 17.27: FrmMediaPlayer.vb  2  ' Windows Media Player control used to play media files.  3  Public Class FrmMediaPlayer  4     ' open new media file in Windows Media Player  5     Private Sub openItem_Click(ByVal sender As System.Object, _  6        ByVal e As System.EventArgs) Handles openItem.Click  7  8        openMediaFileDialog.ShowDialog()  9 10        ' load and play the media clip 11        player.URL = openMediaFileDialog.FileName 12     End Sub ' openItem_Click 13 14     ' exit program when exit menu item is clicked 15     Private Sub exitItem_Click(ByVal sender As System.Object, _ 16        ByVal e As System.EventArgs) Handles exitItem.Click 17 18        Application.Exit() 19     End Sub ' exitItem_Click 20  End Class ' FrmMediaPlayer 

The Windows Media Player control provides several buttons that allow the user to play the current file, pause, stop, play the previous file, rewind, forward and play the next file. The control also includes a volume control and trackbars to select a specific position in the media file.

Our application provides a File menu containing the Open and Exit menu items. When a user chooses Open from the File menu, event handler openItem_Click (lines 512) executes. An OpenFileDialog box displays (line 8) to allow the user to select a file. The program then sets the URL property of the player (the Windows Media Player control object of type AxMediaPlayer) to the name of the file chosen by the user. The URL property specifies the file that Windows Media Player is currently using.

The exitItem_Click event handler (lines 1519) executes when the user selects Exit from the File menu. This event handler simply calls Application method Exit to terminate the application. We provide sample audio and video files in the directory that contains this example.



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net