菜鸟教程小白 发表于 2022-12-12 09:07:33

ios - AVPlayer 无法在 iOS 9 上播放


                                            <p><p>我正在尝试构建一个音频流应用程序,例如 radio 。这是流的 URL:<code>http://radio.livesh.com.br:8068/</code></p>

<p>这基本上是我的做法:</p>

<pre><code>player = AVPlayer()
let playerItem = AVPlayerItem( URL:NSURL(string:streamURL)! )
player = AVPlayer(playerItem:playerItem)
player.rate = 1.0;
player.play()
</code></pre>

<p><code>player</code> 变量被存储,因此它可以继续播放并且不会被取消初始化。在装有 iOS 8 的 iPhone 5S 中,它可以工作,我可以听到声音。在装有 iOS 9 的 iPhone 6 中则不然。</p>

<p>我做错了什么?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>可能是 ATS(应用程序传输安全),它强制使用 https 而不是 http</p>

<p>您可以通过 https 提供您的内容,或者在 info.plist 文件上创建一个异常(exception):</p>

<pre><code>&lt;key&gt;NSAppTransportSecurity&lt;/key&gt;
&lt;dict&gt;
&lt;key&gt;NSExceptionDomains&lt;/key&gt;
&lt;dict&gt;
    &lt;key&gt;radio.livesh.com.br&lt;/key&gt;
    &lt;dict&gt;
      &lt;key&gt;NSTemporaryExceptionAllowsInsecureHTTPLoads&lt;/key&gt;
      &lt;true/&gt;
    &lt;/dict&gt;
&lt;/dict&gt;
&lt;/dict&gt;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - AVPlayer 无法在 iOS 9 上播放,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/32850324/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/32850324/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - AVPlayer 无法在 iOS 9 上播放