首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >HLS视频不是在模拟器和真实设备上播放的。

HLS视频不是在模拟器和真实设备上播放的。
EN

Stack Overflow用户
提问于 2018-10-26 08:31:51
回答 2查看 1.9K关注 0票数 3

我正在开发一个iOS应用程序,它只播放实时流HLS视频。

我的问题是,我已经使用AVPlayer和视图控制器来设置操场,所有的事情都很好--视图控制器已经启动,播放器也已经启动,但是流没有启动。流是一种.m3u8类型,在safari和chrome中工作非常好。无论是在模拟器上还是在真实设备上,iOS都不给我看视频。

我也在寻找其他的解决方案,但它们都没有从我身上奏效。

代码语言:javascript
运行
复制
 /* 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()
    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-27 10:29:26

我使用的HTTP不安全,因此它不允许设备或模拟器播放它。我设置了一个异常,以允许不安全的协议,使iOS能够顺利地流到HLS。

代码语言:javascript
运行
复制
 <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <true/>
        <key>NSExceptionAllowsInsecureHTTPLoads</key>
        <true/>
        <key>NSIncludesSubdomains</key>
        <true/>
    </dict>

票数 0
EN

Stack Overflow用户

发布于 2020-02-03 09:15:32

接受的答案似乎是不正确的,在我的情况下,我也有同样的问题,并添加了ATS特定的所有任意负载配置。

在我做了所有的尝试之后,修正是如果url是从" http“开始的,那么ATS可以很容易地停止一个url,所以如果我们有非安全的"http”url,就可以将http替换为url中的https。

代码语言:javascript
运行
复制
<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>

斯威夫特

代码语言:javascript
运行
复制
let httpsurl = httpURLString.stringByReplacingOccurrencesOfString("http", withString: "https")

Obj-C:

代码语言:javascript
运行
复制
NSString *httpsurl = [httpURLString stringByReplacingOccurrencesOfString:@“http” withString:@“https”];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53004636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档