Chapter 10. Multimedia
Introduction
The recipes in this chapter provide routines for playing sound files and for displaying video clips and photos. One recipe even demonstrates the “new” functionality of Visual Basic 2005 that commands your computer’s internal speaker to emit a system-dependent beep. (That takes us back a few years!) More advanced recipes let you process the JPEG photos from your digital camera. No longer is C++ coding required to manipulate images with respectable speed. Visual Basic programmers now have access to a full set of powerful multimedia-processing features built right into .NET.
10.1. Playing an Audio File
Problem
You want to play a sound clip file, a system sound, or a music file such as an MP3.
Solution
Several different objects and system utilities are available to play sound clips or media files. In this recipe we’ll demonstrate the use of:
My.Computer.Audio.Play()
andSoundPlayer
to play audio clip files such as WAV filesMy.Computer.Audio. PlaySystemSound()
to play operating-system-assigned soundsProcess.Start()
to activate Windows Media Player to play MP3 and other media files
Discussion
The code required to play an audio sample is actually quite
short. In most cases, a single line of code is all it takes to play a
sound. Visual Basic 2005’s new My
namespace provides a lot of new easy-to-use functionality. The
My.Computer.Audio.Play()
method is a good example. Simply pass this method the name of an audio file and the play mode that controls how the sound ...
Get Visual Basic 2005 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.