HLS视频在模拟器和真实设备上无法播放

3
我正在开发一款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()
    }

请查看编辑后的帖子。 - Fariha Hasan
一切似乎都很正常。你尝试检查玩家的“error”属性了吗?另外,试着在玩家的“status”属性上放置一个观察者。 - mag_zbc
2个回答

0

被接受的答案在我的情况下似乎不正确,我遇到了同样的问题,并添加了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”];

-1

我使用的是不安全的HTTP URL,因此它不允许设备或模拟器播放。我添加了一个例外来允许不安全的协议,这使得iOS可以流畅地播放HLS。

 <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <true/>
        <key>NSExceptionAllowsInsecureHTTPLoads</key>
        <true/>
        <key>NSIncludesSubdomains</key>
        <true/>
    </dict>

enter image description here


根据苹果公司有关ATS的文档(再次阅读),它不应该起作用。 - SaadurRehman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接