O'Reilly logo

Visual Basic 2005 Cookbook by Tim Patrick, John Clark Craig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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() and SoundPlayer to play audio clip files such as WAV files

  • My.Computer.Audio. PlaySystemSound() to play operating-system-assigned sounds

  • Process.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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required