Recipe 10.3. Playing a Video File


Problem

You want to play video clips from your Visual Basic 2005 application.

Solution

The Process.Start() method lets you automate the playing of video clips in a very reliable and standardized way. Figure 10-3 shows a video run in Windows Media Player using this method.

Figure 10-3. You can launch Windows Media Player from your .NET app to play video clips


Discussion

The Process object lets you run an external application explicitly or implicitly: you can run an application and pass it a specific file to open and run, or you can pass a file and let the operating system implicitly run the associated application based on the filename's extension. This is a good way to play a video clipthe user's media player of choice is automatically launched to play the clip.

Another advantage of the Process object is its simplicity. The following two lines of code create an instance of the Process class, run a shared method to load and start an AVI file, and wait for the media player to exit:

 Dim videoProgram As Process = Process.Start("sample.avi") videoProgram.WaitForExit( ) 




Visual Basic 2005 Cookbook(c) Solutions for VB 2005 Programmers
Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))
ISBN: 0596101775
EAN: 2147483647
Year: 2006
Pages: 400

Similar book on Amazon

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