overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() downloadfileFromURL(url: URL(string: mainPrevIEwURL)!)}func downloadfileFromURL(url: URL) { var downloadTask = URLSessionDownloadTask() downloadTask = URLSession.shared.downloadTask(with: url,completionHandler: { customURL,response,error in self.play(url: customURL!) }) downloadTask.resume()}func play(url: URL) { do { player = try AVAudioPlayer(contentsOf: url) try AVAudioSession.sharedInstance().setcategory(AVAudioSessioncategoryPlayback) player!.preparetoPlay() player!.play() } catch { print(error) }}解决方法 使do语句中的代码如下所示:
let songData = try NSData(contentsOfURL: songURL!,options: NSDataReadingOptions.mappedIfSafe) try AVAudioSession.sharedInstance().setcategory(AVAudioSessioncategoryPlayback) try AVAudioSession.sharedInstance().setActive(true) player = try AVAudioPlayer(data: songData!,fileTypeHint: AVfileTypeMpegLayer3) player!.preparetoPlay() player!.play()总结
以上是内存溢出为你收集整理的ios – 错误域= NSOSStatusErrorDomain代码= 1954115647“(null)”全部内容,希望文章能够帮你解决ios – 错误域= NSOSStatusErrorDomain代码= 1954115647“(null)”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)