Delphi multimedia design-tmediaplayer component (I)

Source: Internet
Author: User

VCL provides the mediaplayer component for simple multimedia operations. This component is located in the palette component system.

This component can play wave files, MIDI files, Avi videos, and so on. If you just play a wave file, you often use the playsound function in the previous lecture. You can also use more complex mediaplayer components.

The simplest way to use the tmediaplayer component is to drag it to the form. For example:

The form displays the playback control buttons, including play, pause, stop, next, previous, step, back, record, and eject. In the middle.

The most basic form of mediaplayer is to set the filename attribute of the tmediaplayer component to a valid multimedia file name, and then click play on the mediaplayer. Multimedia files can be any WAV, mid, or AVI files. mediaplayer knows how to automatically process these files. If you want tmediaplayer to do something more interesting, you need to know more.

Although mediaplayer control buttons are useful sometimes, you sometimes need to use mediaplayer without control buttons to play and start mediaplayer operations through code, if you do not want to see the mediaplayer control button in the running stage, you can set its visible attribute to false.

 

Mediaplayer attributes, methods, and events (mediaplayer properties, methods, and events)

Tmediaplayer has many attributes. Most of them are easy to understand. However, it is complicated. The following table lists the main attributes of tmediaplayer.

Table 1. main attributes of tmediaplayer

Attribute Description
Autoopen Determines if the media player is opened automatically when the application is run.
If you have enabled the player, the device is enabled. The default value is false.
Autorewind Determines if the media player control rewinds before playing or recording.
If this parameter is set to true, after a Media Player is played, the Media Position pointer is reset to the media start point. The default value is true.
Devicetype Specifies a multimedia device type to open the media player.
Multimedia device type. When you set it to dtautoselect, You can automatically select the device type based on the extension of the file name. The default value is dtautoselect.
Display Specifies the display window for an multimedia device that uses a window for output.
Used to set the display window of a media device.
Displayrect Specifies a rectangular area in the control specified by the display property that is used to display output from a multimedia device.
It is used to set the size and position of the media device playback window, and re-determine the video size to adapt to the rectangular box.
Enablebuttons Determines which buttons on the Media Player are usable.
Determines whether the playback control button is allowed. All buttons by default.
Endpos Specifies the position within the currently loaded medium at which to stop playing or recording.
The end position of the media. The start and end ends of the media. If no endpos is specified, the media is completely played. The endpos value is dependent on the playback type.
Error Specifies the MCI error code returned by the media control method.
The error code of the last operation.
Errormessage Describes the error code stored in the error property.
Text description of the most recent error.
Frame Specifies the number of frames moved forward or backward.
The number of frames to be moved when the back or next method is called or when the back or next button in the mediaplayer control bar is clicked.
Length Specifies the length of the medium in the open multimedia device.
Media length. The length value depends on the media type to be played and the value of timeformat.
Mode Indicates the state of the currently open multimedia device.
Device status, which can be mpnotready, mpstopped, mpplaying, mprecording, mpseeking, mppaused, or mpopen.
Notify Determines whether an onnotify event is generated.
If this parameter is set to true, an onnotify event is generated when the mediaplayer completes an operation.
Y value Indicates the result of the last media control method that requested a notification.
The result of the last notification operation. It can be nvsuccessful, nvsuperseded, nvaborted or nvfailure.
Position Specifies the current position within the currently loaded medium.
The current position of the media.
Startpos Specifies the position within the currently loaded medium from which to begin playing or recording.
Media start point. The media starts playing from startpos to endpos. If startpos is not specified, the media starts playing from the beginning. The value of startpos is dependent on the media type.
Timeformat Determines the format used to specify position information.
Use the time format of the media device. The time format can be millisecond, frame, byte, sampling, track/minute/second, hour/minute/second, and other formats.
Tracks Specifies the number of playable tracks on the open multimedia device.
Number of channels contained by the media (for CD devices)
Visiblebuttons Indicates which of the buttons on the Media Player are visible.
Specifies the button displayed on the mediaplayer control bar. All buttons are displayed by default.
Wait Determines whether a media control method returns control to the application only after it has been completed.
Decide whether to control the call immediately or return after the media is played.

 

The mediaplayer component also has many methods. Many of these methods have the same functions as the control bar buttons. The following table lists the main tmediaplayer methods.

Table 2. Main tmediaplayer Methods
Method Description
Back Steps backward a number of frames (determined by the value of the frames property) in the currently loaded medium.
The number of frames specified by the frame attribute for media playback.
Close Closes the open multimedia device.
Disable the device.
Eject Releases the loaded medium from the open multimedia device.
If appropriate, exit the media (for example, exit the CD ).
Next Moves to the beginning of the next track of the currently loaded medium.
Start the next rail for the device that supports the rail.
Open Opens a multimedia device.
Open the device (when the autoopen attribute is false ).
Pause Toggles the open multimedia device on or off.
Pause playing or recording.
Play Plays the media loaded in the open multimedia device.
Start playing the device.
Previous Sets the current position to the beginning of the previous track if the position was at the beginning of a track when previous was called.
Move to the start point of the previous audio track.
Resume Resumes playing or recording the currently paused multimedia device.
Resume pause interruption.
Rewind Sets the current position to the beginning of the medium, which is stored in the Start property.
Reset the media position to the beginning of the media.
Save Saves the currently loaded medium to the file specified in the filename property.
Store the media in the file specified by the filename attribute.
Startrecording Begins recording from the current position or from the position specified in startpos.
Start recording data.
Step Moves forward a number of frames (determined by the frames property) in the currently loaded medium.
Advances the number of frames specified by the frame attribute.
Stop Halts playing or recording.
Stop playing or recording.

 

The mediaplayer component has only one important event. Every time a command is completed, the onnotify event is called, but only when the notify attribute is set to true. The error and policyvalue attributes can be checked to determine whether the operation is successful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.