|
1 | 1 | import AVFoundation |
2 | 2 |
|
3 | 3 | public class AudioUtils { |
4 | | - public static func audioSessionModeFromString(_ mode: String) -> AVAudioSession.Mode { |
5 | | - let retMode: AVAudioSession.Mode = switch mode { |
6 | | - case "default_": |
7 | | - .default |
8 | | - case "voicePrompt": |
9 | | - if #available(iOS 12.0, *) { |
10 | | - .voicePrompt |
11 | | - } else { |
12 | | - .default |
13 | | - } |
14 | | - case "videoRecording": |
15 | | - .videoRecording |
16 | | - case "videoChat": |
17 | | - .videoChat |
18 | | - case "voiceChat": |
19 | | - .voiceChat |
20 | | - case "gameChat": |
21 | | - .gameChat |
22 | | - case "measurement": |
23 | | - .measurement |
24 | | - case "moviePlayback": |
25 | | - .moviePlayback |
26 | | - case "spokenAudio": |
27 | | - .spokenAudio |
28 | | - default: |
29 | | - .default |
| 4 | + public static func audioSessionModeFromString(_ mode: String) -> AVAudioSession.Mode { |
| 5 | + let retMode: AVAudioSession.Mode = |
| 6 | + switch mode { |
| 7 | + case "default_": |
| 8 | + .default |
| 9 | + case "voicePrompt": |
| 10 | + if #available(iOS 12.0, *) { |
| 11 | + .voicePrompt |
| 12 | + } else { |
| 13 | + .default |
30 | 14 | } |
31 | | - return retMode |
32 | | - } |
| 15 | + case "videoRecording": |
| 16 | + .videoRecording |
| 17 | + case "videoChat": |
| 18 | + .videoChat |
| 19 | + case "voiceChat": |
| 20 | + .voiceChat |
| 21 | + case "gameChat": |
| 22 | + .gameChat |
| 23 | + case "measurement": |
| 24 | + .measurement |
| 25 | + case "moviePlayback": |
| 26 | + .moviePlayback |
| 27 | + case "spokenAudio": |
| 28 | + .spokenAudio |
| 29 | + default: |
| 30 | + .default |
| 31 | + } |
| 32 | + return retMode |
| 33 | + } |
33 | 34 |
|
34 | | - public static func audioSessionCategoryFromString(_ category: String) -> AVAudioSession.Category { |
35 | | - let retCategory: AVAudioSession.Category = switch category { |
36 | | - case "ambient": |
37 | | - .ambient |
38 | | - case "soloAmbient": |
39 | | - .soloAmbient |
40 | | - case "playback": |
41 | | - .playback |
42 | | - case "record": |
43 | | - .record |
44 | | - case "playAndRecord": |
45 | | - .playAndRecord |
46 | | - case "multiRoute": |
47 | | - .multiRoute |
48 | | - default: |
49 | | - .soloAmbient |
50 | | - } |
51 | | - return retCategory |
52 | | - } |
| 35 | + public static func audioSessionCategoryFromString(_ category: String) -> AVAudioSession.Category { |
| 36 | + let retCategory: AVAudioSession.Category = |
| 37 | + switch category { |
| 38 | + case "ambient": |
| 39 | + .ambient |
| 40 | + case "soloAmbient": |
| 41 | + .soloAmbient |
| 42 | + case "playback": |
| 43 | + .playback |
| 44 | + case "record": |
| 45 | + .record |
| 46 | + case "playAndRecord": |
| 47 | + .playAndRecord |
| 48 | + case "multiRoute": |
| 49 | + .multiRoute |
| 50 | + default: |
| 51 | + .soloAmbient |
| 52 | + } |
| 53 | + return retCategory |
| 54 | + } |
53 | 55 |
|
54 | | - public static func audioSessionCategoryOptionsFromStrings(_ options: [String]) -> AVAudioSession.CategoryOptions { |
55 | | - var categoryOptions: AVAudioSession.CategoryOptions = [] |
56 | | - for option in options { |
57 | | - switch option { |
58 | | - case "mixWithOthers": |
59 | | - categoryOptions.insert(.mixWithOthers) |
60 | | - case "duckOthers": |
61 | | - categoryOptions.insert(.duckOthers) |
62 | | - case "allowBluetooth": |
63 | | - categoryOptions.insert(.allowBluetooth) |
64 | | - case "allowBluetoothA2DP": |
65 | | - categoryOptions.insert(.allowBluetoothA2DP) |
66 | | - case "allowAirPlay": |
67 | | - categoryOptions.insert(.allowAirPlay) |
68 | | - case "defaultToSpeaker": |
69 | | - categoryOptions.insert(.defaultToSpeaker) |
70 | | - case "interruptSpokenAudioAndMixWithOthers": |
71 | | - if #available(iOS 13.0, *) { |
72 | | - categoryOptions.insert(.interruptSpokenAudioAndMixWithOthers) |
73 | | - } |
74 | | - case "overrideMutedMicrophoneInterruption": |
75 | | - if #available(iOS 14.5, *) { |
76 | | - categoryOptions.insert(.overrideMutedMicrophoneInterruption) |
77 | | - } |
78 | | - default: |
79 | | - break |
80 | | - } |
| 56 | + public static func audioSessionCategoryOptionsFromStrings(_ options: [String]) -> AVAudioSession.CategoryOptions { |
| 57 | + var categoryOptions: AVAudioSession.CategoryOptions = [] |
| 58 | + for option in options { |
| 59 | + switch option { |
| 60 | + case "mixWithOthers": |
| 61 | + categoryOptions.insert(.mixWithOthers) |
| 62 | + case "duckOthers": |
| 63 | + categoryOptions.insert(.duckOthers) |
| 64 | + case "allowBluetooth": |
| 65 | + categoryOptions.insert(.allowBluetooth) |
| 66 | + case "allowBluetoothA2DP": |
| 67 | + categoryOptions.insert(.allowBluetoothA2DP) |
| 68 | + case "allowAirPlay": |
| 69 | + categoryOptions.insert(.allowAirPlay) |
| 70 | + case "defaultToSpeaker": |
| 71 | + categoryOptions.insert(.defaultToSpeaker) |
| 72 | + case "interruptSpokenAudioAndMixWithOthers": |
| 73 | + if #available(iOS 13.0, *) { |
| 74 | + categoryOptions.insert(.interruptSpokenAudioAndMixWithOthers) |
| 75 | + } |
| 76 | + case "overrideMutedMicrophoneInterruption": |
| 77 | + if #available(iOS 14.5, *) { |
| 78 | + categoryOptions.insert(.overrideMutedMicrophoneInterruption) |
81 | 79 | } |
82 | | - return categoryOptions |
| 80 | + default: |
| 81 | + break |
| 82 | + } |
83 | 83 | } |
| 84 | + return categoryOptions |
| 85 | + } |
84 | 86 | } |
0 commit comments