HLS视频无法在模拟器和真实设备上播放 [英] HLS video is not playing on simulator and real device

查看:274
本文介绍了HLS视频无法在模拟器和真实设备上播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个iOS应用程序,该应用程序仅播放实时流HLS视频.

I am working on an iOS app that simply plays the live stream HLS video.

我的问题是我已经使用AVPlayer和视图控制器设置了Playground,启动视图控制器时一切正常,播放器也已启动,但流媒体未启动.该流是.m3u8类型,在Safari和Chrome浏览器中效果非常好. iOS不会在模拟器或真实设备上向我显示视频.

My issue is that I have used AVPlayer and view controller to set up the playground, All things are working fine the view controller is started, the player is also started but the streaming doesn't start. The stream is a type of .m3u8 that works extremely fine in safari and chrome. The iOS doesn't show me up the video either on simulator or real-device.

我还搜索了其他SO解决方案,但是它们都不对我有用.

I have also searched for other SO solutions but neither of them worked from me.

 /* 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()
    }

推荐答案

我正在使用不安全的HTTP URL,因此它不允许设备或模拟器播放它.我放了一个例外,允许不安全的协议让iOS平稳地传输HLS.

I was using HTTP URL which is not secured thus, it doesn't allow device or simulator to play it. I put an exception to allow insecure protocols which let the iOS to stream the HLS smoothly.

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

这篇关于HLS视频无法在模拟器和真实设备上播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆