我正在开发一个 iOS 应用程序,它可以简单地播放实时流 HLS 视频。
我的问题是我已经使用 AVPlayer 和视图控制器来设置游乐场,所有事情都工作正常,视图控制器已启动,播放器也已启动,但流媒体未启动。该流是一种 .m3u8 类型,在 safari 和 chrome 中运行得非常好。 iOS 不会在模拟器或真实设备上显示视频。
我还搜索了其他 SO 解决方案,但它们都对我不起作用。
/* Button to play live news streaming */
@IBAction func liveNews(_ sender: Any)
{
guard let NewsUrl = URL(string: "http://cdn39.live247stream.com/A1TVuk/tv/playlist.m3u8")
else {
return }
/* Create an AV PLAYER and passed the HLS URL to it */
let player = AVPlayer(url: NewsUrl)
player.allowsExternalPlayback = true
/* Setup a player view controller to handle the stream */
let playerViewController = AVPlayerViewController()
playerViewController.player = player
/* Using method of play() to load and play the stream */
present(playerViewController, animated: true){
playerViewController.player?.play()
}
在我的情况下,接受的答案似乎不正确,我遇到了同样的问题,并添加了 ATS 特定的所有任意负载配置,无法正常工作。
在我尝试了所有方法之后,解决方法是,如果 url 以“http”开头,ATS 会立即停止该 url,因此如果我们有非安全的“http”url,则将 url 中的 http 替换为 https 对我有用。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>some.url.to.com.countrycode</key>
<dict>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
Swift:
let httpsurl = httpURLString.stringByReplacingOccurrencesOfString("http", withString: "https")
Obj-C:
NSString *httpsurl = [httpURLString stringByReplacingOccurrencesOfString:@“http” withString:@“https”];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)