Swift 如何解决这个问题';所需条件为false:format.sampleRate==hwFormat.sampleRate';错误?
我正在使用AVPlayer播放本地文件和在线URL的声音。 但是我犯了一个错误,找不到原因。我搜索了一下,但找不到答案。 这是我的错误: 由于未捕获异常而终止应用程序 'com.apple.coreaudio.avfaudio',原因:'所需条件为假: format.sampleRate==hwFormat.sampleRate' 这是我的密码:Swift 如何解决这个问题';所需条件为false:format.sampleRate==hwFormat.sampleRate';错误?,swift,avplayer,Swift,Avplayer,我正在使用AVPlayer播放本地文件和在线URL的声音。 但是我犯了一个错误,找不到原因。我搜索了一下,但找不到答案。 这是我的错误: 由于未捕获异常而终止应用程序 'com.apple.coreaudio.avfaudio',原因:'所需条件为假: format.sampleRate==hwFormat.sampleRate' 这是我的密码: var globalPlayer = AVPlayer() let asset = AVURLAsset.init(url: url, options
var globalPlayer = AVPlayer()
let asset = AVURLAsset.init(url: url, options: nil)
let item = AVPlayerItem.init(asset: asset)
globalPlayer = AVPlayer.init(playerItem: item)
globalPlayer.volume = 1
globalPlayer.play()
请帮帮我,非常感谢 我的代码看起来很简单,而且很有效
class Player{
var avplayer : AVPlayer?;
function play(){
self.avplayer = AVPlayer(url: url)
self.avplayer?.volume = 1.0
self.avplayer?.play()
}
}
可能是设备不支持您的源的采样率?您尝试过不同的来源吗?使用
AVPlayer
,这是一个不寻常的错误。你能分享音频文件的url吗?Yannick,哦,也许你是对的,我的代码可以工作,但有时会崩溃,不是每次,我会检查源代码。谢谢你的建议。@Fistman:let SilenceeAudioPath=Bundle.main.path(forResource:“demo_sound”,of type:“mp3”),我想问题不在于url