在Delphi XE5 / Android平台上播放声音提示/哔声 [英] Play a sound alert/beep on Delphi XE5/Android platform

查看:594
本文介绍了在Delphi XE5 / Android平台上播放声音提示/哔声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Delphi XE5 / Android平台上播放声音提示/哔声?



我想要实现的是如何播放系统警报/蜂鸣声像Windows应用程序使用Beep功能或至少找到系统音频文件的路径,以便我可以根据事件运行特定的音频文件。

解决方案

我最终使用资源文件播放我的自定义音频文件。



步骤:


  1. 从Delphi IDE单击项目。

  2. 然后选择资源和图像...。

  3. 选择您的媒体文件并将其设置为RCDATA。

  4. 记住您的资源标识符。

注意:确保媒体类型受TMediaPlayer支持,否则将无法正常工作。



Delphi程序: p>

 程序PlayAudio(ResourceID:string); 
var
ResStream:TResourceStream;
TmpFile:string;
begin
ResStream:= TResourceStream.Create(HInstance,ResourceID,RT_RCDATA);
try
TmpFile:= TPath.Combine(TPath.GetTempPath,'tmp.mp3');

ResStream.Position:= 0;
ResStream.SaveToFile(TmpFile);
MediaPlayer1.FileName:= TmpFile;

MediaPlayer1.Play;

finally
ResStream.Free;
结束
结束

用法:

 code> PlayAudio('Resource_1'); 


Is there any way to play a sound alert/beep on Delphi XE5/Android platform?

What I'm trying to achieve is how to play system alert/beep sound like Windows application using Beep function or at least find the path of system's audio files so I can run specific audio file based on an event.

解决方案

I ended up using resource files to play my custom audio file.

Steps:

  1. From Delphi IDE click on "Project".
  2. Then select "Resources and Images...".
  3. Choose your media file and set it as RCDATA.
  4. Remember your resource identifier.

Note: Make sure the media type is supported by TMediaPlayer otherwise it won't work.

Delphi Procedure:

procedure PlayAudio(ResourceID: string);
var
  ResStream: TResourceStream;
  TmpFile: string;
begin
  ResStream := TResourceStream.Create(HInstance, ResourceID, RT_RCDATA);
  try
    TmpFile := TPath.Combine(TPath.GetTempPath, 'tmp.mp3');

    ResStream.Position := 0;
    ResStream.SaveToFile(TmpFile);
    MediaPlayer1.FileName := TmpFile;

    MediaPlayer1.Play;

  finally
    ResStream.Free;
  end;
end;

Usage:

PlayAudio('Resource_1');

这篇关于在Delphi XE5 / Android平台上播放声音提示/哔声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆