是否为端口扬声器(类型:扬声器)选择了未知的数据源? [英] Unknown selected data source for Port Speaker (type: Speaker)?

查看:478
本文介绍了是否为端口扬声器(类型:扬声器)选择了未知的数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我多次在cat日志中收到此消息:

i am getting this message in cat log multiple times :

[avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)

我正在使用此代码播放背景音乐:

i am using this code to playback background music :

  let path = Bundle.main.path(forResource: fileName, ofType:"mp3")!
        let url = URL(fileURLWithPath: path)

        do {
                let sound = try AVAudioPlayer(contentsOf: url)
                self.player = sound
                sound.prepareToPlay()
                sound.volume = 0.05
                sound.numberOfLoops = loops
                sound.play()
        } catch {
            print("[PLAY SOUND][DELEGATE] error loading file -> \(fileName)")
        }

我进行了研究,发现了类似的问题,因此我在viewdidload中添加了音频类别:

i made a research and i found similar issues so i've added the audio category in viewdidload :

  do {
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault)
            try AVAudioSession.sharedInstance().setActive(true)
        } catch {
            print(error)
        }

添加以上代码后,即使手机处于静音模式,背景音乐仍在播放!并且Unknown selected data source for Port Speaker (type: Speaker)的调试器消息仍然显示

after i've added the above code , the background music is playing even if the phone on silent mode ! and the debugger message for Unknown selected data source for Port Speaker (type: Speaker) is still showing

推荐答案

消息Unknown selected data source for Port Speaker似乎是iOS 12的问题.显然,即使代码正在工作,也会出现一些警告.也许Apple会很快解决此问题,所以也许现在您可以忽略此警告,一旦他们找到解决方案,您就可以使其静音.

The message Unknown selected data source for Port Speaker seems to be a problem with iOS 12. Apparently it's some warning that appears even if the code is working. Perhaps Apple will fix this soon, so maybe for now you can ignore this warning and once they find a solution you will be able to silence it.

来源: iOS 12中的AVAudioSession错误

至于在静音模式下播放背景音乐,这是因为您选择了AVAudioSessionCategory.根据AVAudioSessionCategoryPlayback文档():

As for the background music playing on silent mode, it's because of the AVAudioSessionCategory you selected. According to AVAudioSessionCategoryPlayback documentation (source):

使用此类别时,您的应用音频会继续将静音"开关设置为无声"或屏幕锁定.

When using this category, your app audio continues with the Silent switch set to silent or when the screen locks.

取决于您应用的样式,也许您可​​以使用AVAudioSessionCategorySoloAmbient():

Depending on the style of your app, maybe you could use AVAudioSessionCategorySoloAmbient (source):

您可以通过屏幕锁定和静音开关(在iPhone上称为铃声/静音"开关)使音频静音.

Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).

或者AVAudioSessionCategoryAmbient():

此类别也适用于伴奏"风格的应用程序,例如用户在播放音乐"应用程序时演奏的虚拟钢琴.使用此类别时,其他应用程序的音频会与您的音频混合在一起.屏幕锁定和静音开关(在iPhone上称为铃声/静音"开关)使您的音频静音.

This category is also appropriate for "play along" style apps, such as a virtual piano that a user plays while the Music app is playing. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).

这篇关于是否为端口扬声器(类型:扬声器)选择了未知的数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆