|
@@ -46,6 +46,11 @@ class TSAudioPlayer {
|
|
|
do {
|
|
|
audioPlayer = try AVAudioPlayer(contentsOf: url)
|
|
|
audioPlayer?.prepareToPlay()
|
|
|
+
|
|
|
+ let audioSession = AVAudioSession.sharedInstance()
|
|
|
+ try audioSession.setCategory(.playback) // 设置类别为 playback
|
|
|
+ try audioSession.setActive(true) // 激活音频会话
|
|
|
+
|
|
|
} catch {
|
|
|
print("音频文件加载失败: \(error.localizedDescription)")
|
|
|
return nil
|