我正在使用库AudioPlayer作为我的应用的播放器,它应该从URL播放.mp3文件。问题是它开始播放,但几秒后就会停止播放并且不会继续播放。
// I have set the Delegate on the VC
class SearchViewController: AudioPlayerDelegate{
// I have instantiated the AudioPlayer
let player = AudioPlayer()
// Set its delegate and some parameter so that it resumes in case of pause(declared in the viewDidLoad)
player.delegate = self
player.resumeAfterInterruption = true
player.resumeAfterConnectionLoss = true
// Function to check and print when stateChanges
func audioPlayer(audioPlayer: AudioPlayer, didChangeStateFrom from: AudioPlayerState, toState to: AudioPlayerState) {
print("State changed from:\(from)to\(to)")
}
// And a function to start Playing
func play(Link: String) {
let item = AudioItem(highQualitySoundURL: NSURL(string: Link))
player.playItem(item!)
}
上面的代码是基本的。当玩家在几秒钟后停止时,这就是didChangeStateFrom函数打印的内容。但它永远不会再次开始播放:
State changed from:BufferingtoPlaying
State changed from:PlayingtoBuffering
State changed from:BufferingtoPlaying
State changed from:PlayingtoBuffering
State changed from:BufferingtoPlaying
State changed from:PlayingtoBuffering
State changed from:BufferingtoPlaying
State changed from:PlayingtoBuffering
State changed from:BufferingtoPlaying
State changed from:PlayingtoBuffering
State changed from:BufferingtoPlaying
State changed from:PlayingtoBuffering
State changed from:BufferingtoPlaying
State changed from:PlayingtoBuffering