4.3.14 Multimedia

Multimedia

"Multimedia" is a buzzword that has an almost nostalgic flair by now. Nevertheless, it hasn't yet found its way to Visual FoxPro. One might argue that Visual FoxPro is used to create business applications and therefore, multimedia isn't really important. However, I don't agree. Sounds and videos are used all over the place. AVI files are used for all kinds of animations such as in the File Copy Progress dialog provided by Windows Explorer. I can think of a hundred places where I'd like to use such animations in my application.

The two classes I introduce in this category provide all the functionality you need to introduce the flair of multimedia to your applications.

Sound Player

Class

_soundplayer

Base class

Container

Class library

_multimedia.vcx

Parent class

_container

Sample

...\Samples\Vfp98\Solution\Forms\mci_play.scx

Dependencies

_base.vcx

The Sound Player foundation class can be used to play sound files such as AVI and MDI. The Sound Player class achieves this by making Windows API calls rather than using any ActiveX controls.

Playing sounds has been made easy with this class. All sound-playing features are accessible through a handful of properties and methods. To play a sound file, simply drop this class on a form (or any other kind of container) and set the cFileName property. When instantiated, the sound player object automatically plays the specified sound file until it is destroyed or until somebody triggers a PauseSound() or CloseSound() message. The sound file is automatically played, because the lAutoOpen and the lAutoPlay properties are set to .T. by default. The first property defines that the specified sound file is automatically opened on Init(). The second property makes sure the sound file is automatically played when loaded. If you set the lAutoOpen property to .F., you have to open the file manually using the OpenSound() method. If lAutoPlay is still set to .T., the sound will automatically be played after opening the file. If it is set to .F., you also have to trigger the playing manually by sending a PlaySound() method. Once a sound is played, it repeats endlessly, because this is the default setting specified in the AutoRepeat property. Again, you can set this property to .F. to play the sound only once. At any time while a sound is being played, you can pause it by sending a PausePlay() message. This can be useful when you want to change the actual play position. You can set the position using the SetPosition() method, which uses parameters of "Start", "End", or a position in milliseconds (still passed as a character string). You can resume playing at any time by issuing the PlaySound() message. Once you are done playing a sound, you can close the sound file using the CloseSound() method, or simply by destroying the Sound Player object.

The Sound Player even provides data binding. You can use the ControlSource property to specify a data source that holds the file name of the sound file. This file name is used internally, just like the cFileName property.

When an error occurs, the Sound Player class displays a message box with the exact error details. This message box is displayed in the ShowMCIError() method. You can overwrite this method to provide your own error handling or error-display algorithms. The properties MCIError and MCIErrorString provide information about the nature of the error.

Video Player

Class

_videoplayer

Base class

Container

Class library

_multimedia.vcx

Parent class

_container

Sample

...\Samples\Vfp98\Solution\Forms\mci_play.scx

Dependencies

_base.vcx

The Video Player works much like the Sound Player, with the exception that it plays videos rather than sounds. The Video Player object has almost the exact same set of methods and properties, but some of the names have been altered to say "Video" instead of "Sound."

Initially, I wondered how to define where the video should be displayed. After browsing the source code, I figured that the Video Player (which is a container class) is set invisible on startup. However, this container is still used to determine the size of the video. Now here is the weird part: The video is always displayed in the currently active window at the size of the Video Player container. When I was experimenting with this class, I used the command window a lot to trigger individual messages, with the result that the video was displayed inside the Visual FoxPro command window. Whether this is a bug or not, I don't know. You can use it to instantiate the Video Player once, but display the video in different windows. On the other hand, this might lead to rather weird bugs where videos show up in windows that don't have anything to do with the video. Unfortunately, it's beyond my knowledge whether this behavior will change in the future, since the Video Player class is almost undocumented.



Advanced Object Oriented Programming with Visual FoxPro 6. 0
Advanced Object Oriented Programming with Visual FoxPro 6.0
ISBN: 0965509389
EAN: 2147483647
Year: 1998
Pages: 113
Authors: Markus Egger

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