如何在Delphi FireMonkey XE4播放系统声音? [英] How to play system sound in Delphi FireMonkey XE4?
问题描述
我想在Windows和Mac OS X都扮演着系统的声音要在Windows播放声音使用的的东西的是这样的:
I want to play system sound in both Windows and MAC OS X. To play sound in Windows used something like this:
PlaySound('C:\Windows\Media\Windows Default.wav', 0, SND_FILENAME + SND_ASYNC);
我相信我一定要使用TMediaPlayer。
I am sure I have to use TMediaPlayer.
推荐答案
您是正确的,你可以使用的 TMediaPlayer 组件,文件明确规定:
You are correct, you can use the TMediaPlayer component, documentation clearly states :
TMediaPlayer播放音频文件和视频的音频分量
文件中。
TMediaPlayer playbacks audio files and the audio component of a video file.
要指定的媒体文件到当前TMediaPlayer播放,
设置FileName属性。文件名的必须包括的路径
文件中,因此它可以在存储器本地化和延长。呼叫
在播放和停止的方法开始播放媒体文件,或者停止或
暂停运行的媒体文件。的当前位置是通过指定
currentTime属性。
To specify the media file to be played by the current TMediaPlayer, set the FileName property. The file name must include the path of the file, so it can be localized on the memory, and the extension. Call the Play and Stop methods to start playing a media file, or to stop or pause a running media file. The current position is specified through the CurrentTime property.
TMediaPlayer也暴露出媒体文件
属性,如时间,VideoSize,卷或国家。
TMediaPlayer also exposes media file properties such as Duration, VideoSize, Volume or State.
关于支持的文件格式(TMedia codecManager)。
该文件规定如下:
使用TMedia codecManager访问,管理和登记codeCS是
播放媒体文件时使用。
Use TMediaCodecManager to access, manage, and register codecs to be used when playing media files.
支持的媒体文件格式为每个本地格式
平台:
The supported media files formats are the native formats for each platform:
对于Windows:的结果
音频格式:.WMA,.MP3,.WAV结果
视频格式:AVI,.WMV
For Windows:
Audio formats: .wma, .mp3, .wav
Video formats: .avi,.wmv
对于Mac OS / iOS的:的结果
音频格式:.MP3,.caf结果
视频格式:MOV格式,的.m4v,.MP4
For Mac OS/iOS:
Audio formats: .mp3, .caf
Video formats: .mov, .m4v, .mp4
使用TMedia codecManager,有可能定制寄存器
媒体codeCS延长了音频/视频功能的支持。
Using TMediaCodecManager, it is possible to register custom media codecs to extend the audio/video feature support.
简单的例子:
procedure TForm1.Button1Click(Sender: TObject);
begin
MediaPlayer1.FileName := 'D:\test.mp3';
MediaPlayer1.Play;
end;
您应该能够在Firemonkey跨平台播放MP3文件,但超出了这个问题的范围。
You should be able to play mp3 files in Firemonkey across platforms but that is out of scope of this question.
这篇关于如何在Delphi FireMonkey XE4播放系统声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!