File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,13 +8,33 @@ namespace iOSNativePlugin
88{
99 public static class Audio
1010 {
11+ [ DllImport ( "__Internal" ) ] static extern float Audio_Init ( Action OnAudioSessionRouteChangedCallback ) ;
1112 [ DllImport ( "__Internal" ) ] static extern float Audio_SystemVolume ( ) ;
1213 [ DllImport ( "__Internal" ) ] static extern double Audio_InputLatency ( ) ;
1314 [ DllImport ( "__Internal" ) ] static extern double Audio_OutputLatency ( ) ;
1415 [ DllImport ( "__Internal" ) ] static extern double Audio_SampleRate ( ) ;
1516 [ DllImport ( "__Internal" ) ] static extern bool Audio_IsBluetoothHeadphonesConnected ( ) ;
1617 [ DllImport ( "__Internal" ) ] static extern void Audio_SetAudioExclusive ( bool exclusive ) ;
1718
19+ static Action onAudioSessionRouteChangedEvent ;
20+
21+ public static event Action OnAudioSessionRouteChangedEvent
22+ {
23+ add
24+ {
25+ Audio_Init ( OnAudioSessionRouteChanged ) ;
26+ onAudioSessionRouteChangedEvent += value ;
27+ }
28+ remove => onAudioSessionRouteChangedEvent -= value ;
29+ }
30+
31+
32+ [ MonoPInvokeCallback ( typeof ( Action ) ) ]
33+ static void OnAudioSessionRouteChanged ( )
34+ {
35+ onAudioSessionRouteChangedEvent ? . Invoke ( ) ;
36+ }
37+
1838 /// <summary>
1939 /// 当前系统音量
2040 /// <para>https://developer.apple.com/documentation/avfaudio/avaudiosession/1616533-outputvolume?language=objc</para>
Original file line number Diff line number Diff line change 22
33@interface Audio : NSObject
44
5+ +(void )Init : (Action)OnAudioSessionRouteChangedCallback ;
56+(float )SystemVolume ;
67+(double )InputLatency ;
78+(double )OutputLatency ;
1314
1415extern " C"
1516{
17+ void Audio_Init (Action OnAudioSessionRouteChangedCallback)
18+ {
19+ [Audio Init: OnAudioSessionRouteChangedCallback];
20+ }
1621 float Audio_SystemVolume ()
1722 {
1823 return [Audio SystemVolume ];
Original file line number Diff line number Diff line change 33
44@implementation Audio
55
6+ static Action onAudioSessionRouteChangedEvent;
7+ static BOOL inited;
8+
9+ +(void )Init : (Action)OnAudioSessionRouteChangedCallback
10+ {
11+ if (inited)
12+ return ;
13+ onAudioSessionRouteChangedEvent = OnAudioSessionRouteChangedCallback;
14+ [[NSNotificationCenter defaultCenter ] addObserver: [Audio class ]
15+ selector: @selector (OnAudioSessionRouteChanged: )
16+ name: AVAudioSessionRouteChangeNotification
17+ object: nil ];
18+ inited = YES ;
19+ }
20+
21+ +(void )OnAudioSessionRouteChanged : (NSNotification *)notification
22+ {
23+ if (onAudioSessionRouteChangedEvent != nil )
24+ onAudioSessionRouteChangedEvent ();
25+ }
26+
27+
628+(float )SystemVolume
729{
830 return [[AVAudioSession sharedInstance ] outputVolume ];
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ static void LOG(NSString* log){
3636 return date;
3737}
3838
39-
39+ typedef void (*Action)();
4040typedef void (*SaveImageToAlbumCallback)(bool );
4141typedef void (*ShareCloseCallback)();
4242typedef void (*FileSavedCallback)(bool );
You can’t perform that action at this time.
0 commit comments