我正在尝试通过AVPlayer播放MP3文件:
let url = URL(string: "http://transom.org/wp-content/uploads/2004/03/stereo_40kbps.mp3?_=7")! let asset = AVURLAsset(url: url) let item = AVPlayerItem(asset: asset) let player = AVPlayer(playerItem: item) player.play()
但是我得到了下一个日志:
2017-09-26 21:57:07.906598+0300 MyApp[7558:1177816] CredStore - performQuery - Error copying matching creds. Error=-25300,query={ class = inet; "m_Limit" = "m_LimitAll"; "r_Attributes" = 1; sync = syna; }
我想这是因为iOS 11和Xcode 9,但我不知道如何解决这个问题.
解决方法
问题似乎与App Transport安全性有关,启用后,它可以在iOS 11中使用以下几组代码正常工作,
您提供的上述URL似乎也有关联的https链接,请使用https链接或允许App Transport安全性
let avPlayerVC = AVPlayerViewController() let url = URL(string: "https://transom.org/wp-content/uploads/2004/03/stereo_40kbps.mp3?_=7")! let asset = AVURLAsset(url: url) let item = AVPlayerItem(asset: asset) let player = AVPlayer(playerItem: item) avPlayerVC.player = player present(avPlayerVC,animated: true) { player.play() }
但是在这里我使用了AVPlayerViewController,并使用了与代码中使用的AVPlayer相同的实例.我不知道你在如何使用AVPlayer,但上述情况很好.