简体   繁体   English

iOS-Swift-AVPlayer:播放包含高棉unicode的网址时出错

[英]iOS - Swift - AVPlayer: Error playing with url containing khmer unicode

I've just built a custom video player with AVPlayer, and I've found that I can only play video with url containing english character(for example: http://app.ournsarath.com/uploads/videos/mp4s/09_03_2018_business.mp4 ). 我刚刚用AVPlayer构建了一个自定义视频播放器,但发现只能播放带有包含英文字符的url的视频(例如: http : //app.ournsarath.com/uploads/videos/mp4s/09_03_2018_business。 mp4 )。 Whenever I pass the url containing khmer unicode(for example: http://app.ournsarath.com/uploads/sound/mp3s/01.06.2018Helpingothersចង់ជួយគ េ.mp4), the player doesn't play at all. 每当我传递包含高棉unicode的URL时(例如: http://app.ournsarath.com/uploads/sound/mp3s/01.06.2018Helpingothersmp.mp4 ),播放器根本不会播放。 I'm new to iOS development. 我是iOS开发的新手。 Any advice or direction would be appreciated. 任何建议或指示,将不胜感激。 Thanks! 谢谢!

I've found a solution by encoding the url string before passing it into AVPlayer. 我已经找到一种解决方案,方法是在将URL字符串传递给AVPlayer之前对其进行编码。

    func setupPlayer(link: String){
    let encodedString = link.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
    if let url = URL(string: encodedString!) {
        player = AVPlayer(url: url)
        let playerLayer = AVPlayerLayer(player: player)
        self.layer.addSublayer(playerLayer)
        playerLayer.frame = self.frame
        player?.play()
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM