Delphi 多媒体(TMediaplayer 1)

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主要属性

属性描述
AutoOpenDetermines if the media player is opened automatically when the application is run.
是否已启动播放程序就打开设备,默认为False。
AutoRewindDetermines if the media player control rewinds before playing or recording.
当为True时,在媒体播放后,媒体位置指针将被重新设置为媒体起点,默认为True。
DeviceTypeSpecifies a multimedia device type to open the media player.
多媒体设备类型。设置成dtAutoSelect时,可根据文件名扩展自动选择设备类型,默认值为dtAutoSelect。
DisplaySpecifies the display window for an multimedia device that uses a window for output.
用于设置媒体设备的显示窗口。
DisplayRectSpecifies a rectangular area in the control specified by the Display property that is used to display output from a multimedia device.
用于设置媒体设备回放窗口的大小和位置,重新确定视频大小以适应矩形框。
EnableButtonsDetermines which buttons on the media player are usable.
决定播放控制按钮是否允许使用。默认为所有按钮。
EndPosSpecifies the position within the currently loaded medium at which to stop playing or recording.
媒体结束位置,媒体播放是从起点到终点(EndPos),如果没有指定EndPos,媒体将全部播放完。所赋EndPos值依赖于播放的类型。
ErrorSpecifies the MCI error code returned by the media control method.
最近一次操作的错误码。
ErrorMessageDescribes the error code stored in the Error property.
最近错误的文本描述。
FrameSpecifies the number of frames moved forward or backward.
调用Back或Next方法时,或点击MediaPlayer控制栏上的Back或Next按钮时所要移动的帧数。
LengthSpecifies the length of the medium in the open multimedia device.
媒体长度,Length值依赖于被播放的媒体类型和TimeFormat的值。
ModeIndicates the state of the currently open multimedia device.
设备状态,可以是mpNotready, mpStopped, mpPlaying, mpRecording, mpSeeking, mpPaused, mpOpen。
NotifyDetermines whether an OnNotify event is generated.
若为True时,当MediaPlayer完成一个操作时,产生OnNotify事件。
Notify ValueIndicates the result of the last media control method that requested a notification.
上次通知操作的结果。可以是nvSuccessful, nvSuperseded, nvAborted或nvFailure。
PositionSpecifies the current position within the currently loaded medium.
媒体当前位置。
StartPosSpecifies the position within the currently loaded medium from which to begin playing or recording.
媒体起点,媒体从StartPos开始播放到EndPos,若没有指定媒体起点StartPos,媒体从头开始播放。所赋StartPos值依赖于媒体类型。
TimeFormatDetermines the format used to specify position information.
使用媒体设备的时间格式。时间格式可以用毫秒、帧、字节、采样、磁道/分/秒、小时/分/秒等格式。
TracksSpecifies the number of playable tracks on the open multimedia device.
媒体所包含的磁道数(对于CD设备来说)
VisibleButtonsIndicates which of the buttons on the media player are visible.
指定MediaPlayer控制栏上显示的按钮,默认为所有按钮。
WaitDetermines whether a media control method returns control to the application only after it has been completed.
决定控制否马上或在媒体播放完之后返回调用。

 

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

表2. TMediaPlayer主要方法

方法描述
BackSteps backward a number of frames (determined by the value of the Frames property) in the currently loaded medium.
将媒体回放由Frame属性指定的帧数。
CloseCloses the open multimedia device.
关闭设备。
EjectReleases the loaded medium from the open multimedia device.
如果合适的话,退出媒体(例如,退出CD)。
NextMoves to the beginning of the next track of the currently loaded medium.
为支持轨道的设备开始下一个轨。
OpenOpens a multimedia device.
打开设备(用于AutoOpen属性为False时)。
PauseToggles the open multimedia device on or off.
暂停播放或录制。
PlayPlays the media loaded in the open multimedia device.
开始设备的播放。
PreviousSets the current position to the beginning of the previous track if the position was at the beginning of a track when Previous was called.
移到前一个音轨的起点。
ResumeResumes playing or recording the currently paused multimedia device.
恢复pause中断的行为。
RewindSets the current position to the beginning of the the medium, which is stored in the Start property.
重新设置媒体位置为媒体的开头。
SaveSaves the currently loaded medium to the file specified in the FileName property.
把媒体存储到FileName属性指定的文件中。
StartRecordingBegins recording from the current Position or from the position specified in StartPos.
开始录制数据。
StepMoves forward a number of frames (determined by the Frames property) in the currently loaded medium.
前移Frame属性指定的帧数。
StopHalts playing or recording.
停止播放或录制。

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值