日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Delphi多媒体设计之TMediaPlayer组件(一)

發布時間:2025/3/20 编程问答 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Delphi多媒体设计之TMediaPlayer组件(一) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

VCL為簡單多媒體操作提供MediaPlayer組件。該組件位于選項板組件System中。

該組件可播放Wave文件、MIDI文件、AVI視頻等等。如果只是簡單的播放Wave文件,常常使用上一講中的PlaySound函數。也可以使用更復雜的MediaPlayer組件。

TMediaPlayer組件最簡單的使用方法就是將其拖放到窗體上。如下圖:

窗體上顯示出播放的控制按鈕,控制按鈕包括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)

TMediaPlayer具有許多屬性。其中大部分都是很容易理解的。但是有些比較復雜。下面的表格中列出了TMediaPlayer的主要屬性。

表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屬性,確定操作是否成功執行。

轉載于:https://www.cnblogs.com/pchmonster/archive/2012/07/12/2588846.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的Delphi多媒体设计之TMediaPlayer组件(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。