引导访问不播放音乐

时间:2019-04-16 15:17:23

标签: ios swift avaudiosession guided-access

我有一个不时播放铃声的应用程序。我的一位应用程序用户说,在引导访问中,此功能将在此之后无法播放。不知道要寻找什么。它确实可以在我的测试设备上运行。我正在使用AVFoundation,这就是我播放mp3的方式。

func playSound(type:String) {
    var source_mp3 = "notification"
    guard let url = Bundle.main.url(forResource: source_mp3, withExtension: "mp3") else { return }

    do {
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        try AVAudioSession.sharedInstance().setActive(true)

        /* The following line is required for the player to work on iOS 11. Change the file type accordingly*/
        player = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue)

        /* iOS 10 and earlier require the following line:
         player = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileTypeMPEGLayer3) */

        guard let player = player else { return }

        player.play()

    } catch let error {
        print(error.localizedDescription)
    }
}

0 个答案:

没有答案