【发布时间】:2015-09-29 10:33:38
【问题描述】:
我希望我只是在某处遗漏了一些东西,我希望在触发本地通知时播放自定义通知声音。
在一个新表单上,我放下了 2 个按钮,btnnotification 和 btnmediaplayer
procedure TForm1.btnnotificationClick(Sender: TObject);
var
MyNotification : TNotification;
begin
MyNotification := NotificationCenter1.CreateNotification;
try
MyNotification.EnableSound := True;
MyNotification.SoundName := TPath.Combine(TPath.GetDocumentsPath, 'Siren.mp3');
MyNotification.Name := 'mynote';
MyNotification.AlertBody := 'Test';
MyNotification.FireDate := Now;
ShowMessage(MyNotification.SoundName); //<-- Points towards a valid filepath
NotificationCenter1.ScheduleNotification(MyNotification);
finally
//MyNotification.DisposeOf;
end;
end;
我将 Siren 文件添加到部署中的内部资产中,通知触发但没有声音,然后我添加了另一个按钮,这次我只是使用 TMediaplayer
procedure TForm1.btnmediaplayerClick(Sender: TObject);
begin
MediaPlayer1.FileName := TPath.Combine(TPath.GetDocumentsPath, 'Siren.mp3');
MediaPlayer1.Play;
ShowMessage(MediaPlayer1.FileName);//<--Points towards the same path as the notification
end;
使用 TMediaplayer 没有问题,这意味着文件确实存在,我现在已经在 2 种不同的设备上进行了尝试:Xperia Z2 和三星 Note 2 都运行 Andriod V4.4.2, 并且两台设备的通知音量都设置为最大,但仍然没有声音。
更新 1
- 我在运行 4.1.2 的三星 Tab3 上尝试过,这意味着它不是 4.4.2 的问题
- 我尝试手动复制 com.andriod.project 文件夹中的文件
但通知仍然没有声音。
已解决:您需要将声音存储在外部并使用 GetSharedDocumentsPath,将其存储在内部并使用 GetDocumentsPath 不起作用
【问题讨论】:
-
看来,你自己解决了这个问题。请发布您的解决方案以及一些详细的解释作为答案,以便您的问题被识别为已回答的问题。
标签: delphi firemonkey