Reputation: 1695
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);
I am sure I have to use TMediaPlayer.
Upvotes: 2
Views: 5439
Reputation: 2977
You are correct, you can use the TMediaPlayer component, documentation clearly states :
TMediaPlayer playbacks audio files and the audio component of a video file.
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 also exposes media file properties such as Duration, VideoSize, Volume or State.
Regarding the supported file formats (TMediaCodecManager).
The documentation states the following:
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:
For Windows:
Audio formats: .wma, .mp3, .wav
Video formats: .avi,.wmvFor Mac OS/iOS:
Audio formats: .mp3, .caf
Video formats: .mov, .m4v, .mp4Using TMediaCodecManager, it is possible to register custom media codecs to extend the audio/video feature support.
Quick example :
procedure TForm1.Button1Click(Sender: TObject);
begin
MediaPlayer1.FileName := 'D:\test.mp3';
MediaPlayer1.Play;
end;
You should be able to play mp3 files in Firemonkey across platforms but that is out of scope of this question.
Upvotes: 3