-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathksSystemSound.pas
More file actions
86 lines (64 loc) · 1.79 KB
/
Copy pathksSystemSound.pas
File metadata and controls
86 lines (64 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
unit ksSystemSound;
interface
{$I ksComponents.inc}
uses System.Classes, ksTypes;
const
libAudioToolbox = '/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox';
type
TksSystemSound = class(TInterfacedObject, IksSystemSound)
public
procedure Play(ASound: TksSound); overload;
procedure Play(ASoundIndex: integer); overload;
end;
implementation
uses Types, System.SysUtils
{$IFDEF ANDROID}
,androidapi.jni.media, FMX.Helpers.Android, androidapi.jni.JavaTypes, Androidapi.JNI.GraphicsContentViewText,Androidapi.JNIBridge,
androidapi.helpers
{$ENDIF}
;
{$IFDEF IOS}
procedure AudioServicesPlaySystemSound( inSystemSoundID: UInt32 ); cdecl; external libAudioToolbox name 'AudioServicesPlaySystemSound';
procedure AudioServicesPlayAlertSound( inSystemSoundID: UInt32 ); cdecl; external libAudioToolbox name 'AudioServicesPlayAlertSound';
{$ENDIF}
procedure TksSystemSound.Play(ASound: TksSound);
var
AId: integer;
begin
AId := -1;
{$IFDEF IOS}
case ASound of
ksMailNew: AId := 1000;
ksMailSent: AId := 1001;
ksVoiceMail: AId := 1002;
ksMessageReceived: AId := 1003;
ksMessageSent: AId := 1004;
ksBeep: AId := 1052;
ksCameraShutter: AId := 1108;
end;
{$ENDIF}
{$IFDEF ANDROID}
case ASound of
ksBeep: AId := 6;
ksCameraShutter: AId := 8;
end;
{$ENDIF}
if AId = -1 then
Exit;
Play(AId);
end;
procedure TksSystemSound.Play(ASoundIndex: integer);
{$IFDEF ANDROID}
var
AAudioMgr : JAudioManager;
{$ENDIF}
begin
{$IFDEF IOS}
AudioServicesPlaySystemSound(ASoundIndex);
{$ENDIF}
{$IFDEF ANDROID}
AAudioMgr := TJAudioManager.Wrap((TAndroidHelper.Activity.getSystemService(TJContext.JavaClass.AUDIO_SERVICE) as ILocalObject).GetObjectID);
AAudioMgr.playSoundEffect(ASoundIndex);
{$ENDIF}
end;
end.