现在的位置: 首页 > 综合 > 正文

Delphi 多媒体(TMediaplayer 1)

2018年02月06日 ⁄ 综合 ⁄ 共 4085字 ⁄ 字号 评论关闭

VCL为简单多媒体操作提供MediaPlayer组件。

该组件可播放Wave文件、MIDI文件、AVI视频等等。如果只是简单的播放Wave文件,常常使用上一讲中的PlaySound函数。也可以使用更复杂的MediaPlayer组件。

 

窗体上显示出播放的控制按钮,控制按钮包括play、pause、stop、next、previous、step、back、record、eject。如上图中。

使用MediaPlayer最基本的形式就是设置TMediaPlayer组件的FileName属性为有效的多媒体文件名,然后并点击MediaPlayer上的play按钮即可。

多媒体文件可任选WAV、MID或AVI文件,MediaPlayer知道怎样自动处理这些文件。如果想要让TMediaPlayer做一些更有趣的事情,就需要了解更深一些了。

尽管有时MediaPlayer的控制按钮很有用,但是,有时候却需要使用不带控制按钮的MediaPlayer,通过代码来实现MediaPlayer的播放、开始等操作,如果不想在运行阶段看到MediaPlayer控制按钮,可以设置它的Visible属性为False。

 


MediaPlayer属性、方法和事件(MediaPlayer Properties, Methods, and Events)

表1. TMediaPlayer主要属性

属性 描述
AutoOpen Determines if the media player is opened automatically when the application is run.

是否已启动播放程序就打开设备,默认为False。
AutoRewind Determines if the media player control rewinds before playing or recording.

当为True时,在媒体播放后,媒体位置指针将被重新设置为媒体起点,默认为True。
DeviceType Specifies a multimedia device type to open the media player.

多媒体设备类型。设置成dtAutoSelect时,可根据文件名扩展自动选择设备类型,默认值为dtAutoSelect。
Display Specifies the display window for an multimedia device that uses a window for output.

用于设置媒体设备的显示窗口。
DisplayRect Specifies a rectangular area in the control specified by the Display property that is used to display output from a multimedia device.

用于设置媒体设备回放窗口的大小和位置,重新确定视频大小以适应矩形框。
EnableButtons Determines which buttons on the media player are usable.

决定播放控制按钮是否允许使用。默认为所有按钮。
EndPos Specifies the position within the currently loaded medium at which to stop playing or recording.

媒体结束位置,媒体播放是从起点到终点(EndPos),如果没有指定EndPos,媒体将全部播放完。所赋EndPos值依赖于播放的类型。
Error Specifies the MCI error code returned by the media control method.

最近一次操作的错误码。
ErrorMessage Describes the error code stored in the Error property.

最近错误的文本描述。
Frame Specifies the number of frames moved forward or backward.

调用Back或Next方法时,或点击MediaPlayer控制栏上的Back或Next按钮时所要移动的帧数。
Length Specifies the length of the medium in the open multimedia device.

媒体长度,Length值依赖于被播放的媒体类型和TimeFormat的值。
Mode Indicates the state of the currently open multimedia device.

设备状态,可以是mpNotready, mpStopped, mpPlaying, mpRecording, mpSeeking, mpPaused, mpOpen。
Notify Determines whether an OnNotify event is generated.

若为True时,当MediaPlayer完成一个操作时,产生OnNotify事件。
Notify Value Indicates the result of the last media control method that requested a notification.

上次通知操作的结果。可以是nvSuccessful, nvSuperseded, nvAborted或nvFailure。
Position Specifies the current position within the currently loaded medium.

媒体当前位置。
StartPos Specifies the position within the currently loaded medium from which to begin playing or recording.

媒体起点,媒体从StartPos开始播放到EndPos,若没有指定媒体起点StartPos,媒体从头开始播放。所赋StartPos值依赖于媒体类型。
TimeFormat Determines the format used to specify position information.

使用媒体设备的时间格式。时间格式可以用毫秒、帧、字节、采样、磁道/分/秒、小时/分/秒等格式。
Tracks Specifies the number of playable tracks on the open multimedia device.

媒体所包含的磁道数(对于CD设备来说)
VisibleButtons Indicates which of the buttons on the media player are visible.

指定MediaPlayer控制栏上显示的按钮,默认为所有按钮。
Wait Determines whether a media control method returns control to the application only after it has been completed.

决定控制否马上或在媒体播放完之后返回调用。

 

MediaPlayer组件还具有很多方法。这些方法许多功能与控制栏按钮相同。下面表格列出了TMediaPlayer主要方法。

表2. TMediaPlayer主要方法

方法 描述
Back Steps backward a number of frames (determined by the value of the Frames property) in the currently loaded medium.

将媒体回放由Frame属性指定的帧数。
Close Closes the open multimedia device.

关闭设备。
Eject Releases the loaded medium from the open multimedia device.

如果合适的话,退出媒体(例如,退出CD)。
Next Moves to the beginning of the next track of the currently loaded medium.

为支持轨道的设备开始下一个轨。
Open Opens a multimedia device.

打开设备(用于AutoOpen属性为False时)。
Pause Toggles the open multimedia device on or off.

暂停播放或录制。
Play Plays the media loaded in the open multimedia 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.

移到前一个音轨的起点。
Resume Resumes playing or recording the currently paused multimedia device.

恢复pause中断的行为。
Rewind Sets the current position to the beginning of the the medium, which is stored in the Start property.

重新设置媒体位置为媒体的开头。
Save Saves the currently loaded medium to the file specified in the FileName property.

把媒体存储到FileName属性指定的文件中。
StartRecording Begins recording from the current Position or from the position specified in StartPos.

开始录制数据。
Step Moves forward a number of frames (determined by the Frames property) in the currently loaded medium.

前移Frame属性指定的帧数。
Stop Halts playing or recording.

停止播放或录制。

 

MediaPlayer组件仅有一个重要的事件。每当完成一个命令时,OnNotify事件被调用,但是只有在Notify属性设置为True时才行。可检验Error和NotifyValue属性,确定操作是否成功执行

抱歉!评论已关闭.