我正在开发一个iOS应用程序,它只播放实时流HLS视频。
我的问题是,我已经使用AVPlayer和视图控制器来设置操场,所有的事情都很好--视图控制器已经启动,播放器也已经启动,但是流没有启动。流是一种.m3u8类型,在safari和chrome中工作非常好。无论是在模拟器上还是在真实设备上,iOS都不给我看视频。
我也在寻找其他的解决方案,但它们都没有从我身上奏效。
/* 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()
}发布于 2018-10-27 10:29:26
我使用的HTTP不安全,因此它不允许设备或模拟器播放它。我设置了一个异常,以允许不安全的协议,使iOS能够顺利地流到HLS。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>

发布于 2020-02-03 09:15:32
接受的答案似乎是不正确的,在我的情况下,我也有同样的问题,并添加了ATS特定的所有任意负载配置。
在我做了所有的尝试之后,修正是如果url是从" http“开始的,那么ATS可以很容易地停止一个url,所以如果我们有非安全的"http”url,就可以将http替换为url中的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>斯威夫特
let httpsurl = httpURLString.stringByReplacingOccurrencesOfString("http", withString: "https")Obj-C:
NSString *httpsurl = [httpURLString stringByReplacingOccurrencesOfString:@“http” withString:@“https”];https://stackoverflow.com/questions/53004636
复制相似问题