These components are automatically wired together so that all you need to provide is a media clip, or sequence, of the appropriate type. You can use these classes:
If you do not need to control the individual components or connections, these classes provide an easy way to play and record time-media data. For more advanced applications, you would explicitly create and connect media components, forming your own media networks. (For more information about media components and networks, read Chapter 12, "Time-media overview.")
Getting started
with audio
The simplest way to play and record audio is to use an instance of TSound. TSound automatically creates the correct audio stream and the necessary audio components to play and record the file. Conceptually, a TSound contains a microphone, an audio player, a speaker, and a gain factor that controls the input and output levels. TSound is derived from TPlayer:
To play an audio clip with TSound:
Playing an audio clip
For example, if you have a sound file named
soundFile
, to create a TSound instance and play the file:
TStandardText soundFile("soundFile"); TSound aSound(soundFile); aSound.PlayFromBegin();
TSound::PlayFromBegin is a shortcut for playing the file from the beginning--it is the same as seeking to the beginning of the file and calling the Play function. Play plays the file from the current position in the file. (When you first instantiate a TSound, the position is TTime::kZero.)
TSound can play the following audio file formats:
To record audio data with TSound:
Recording audio
Recording stops when you run out of space or TSound::Stop() is called.
TSound aSound(soundFile, MOpenFile::kReadWrite);
aSound.AdviseWillRecord();
aSound.Record();
// ...
aSound.Stop();
Getting started
with video
The simplest way to play video data, such as a QuickTime movie, is to create a TMovie instance. TMovie automatically creates the correct video stream and the necessary audio and video components to play the file. Conceptually, a TMovie contains a graphic player, a graphic view, and a TSound. TMovie is derived from TPlayer:
You must call TMovie::CreateView to create a view to display the video part of the movie. You then adopt the resulting view into the root view for the presentation in which you want it to appear. For example, you might set up the movie view as a child view of your document content view and call the TMovie::Play function from the HandleDo function of a command bound to a menu or button. TMovie makes all of the connections needed to play the movie.
NOTE
You can only use movie files in the QuickTime Video format with TMovie.
To play a video clip with TMovie:
To record video data with TMovie:
Playing a
video clip
movieFile
, you can create a TMovie instance and play the movie.
TStandardText movieFile("movieFile");
TMovie myMovie(movieFile);
TView* movieView = myMovie.CreateView
// Adopt view into root view
myMovie.Play();
Recording a
video clip
TMovie aMovie(movieFile, MOpenFile::kReadWrite); aMovie.AdviseWillRecord(); aMovie.Record(); // ... aMovie.Stop();
To play a MIDI clip with TMIDI:
Playing a MIDI clip
MIDIFile
, to create a TMIDI object and play the file:
TStandardText MIDIFile("MIDIFile"); TMIDI aMIDI(MIDIFile); aMIDI.Play();
To record MIDI data with TMIDI:
TMIDI aMIDI(MIDIFile, MOpenFile::kReadWrite); aMIDI.AdviseWillRecord(); aMIDI.Record(); // ... aMIDI.Stop();