iOS-AVPlayer无法从https localhost服务器流式传输视频URL

时间:2019-09-21 08:39:02

标签: ios swift avfoundation avplayer avkit

我正在尝试在iOS上创建流式应用程序。因此,起初我尝试使用http url,但由于他们说出于安全原因,它无法正常工作,因此我使用NanoHTTPD在Android上创建了https服务器,并且能够通过连接了Android和Windows的设备访问新的https服务器同一网络,尽管有警告。现在,我将此添加到了Info.plist文件

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

但是它仍然保持不变,然后我在模拟器上运行了该应用程序,并且日志给了我

    2019-09-21 15:40:07.540419+0800 SampleAVPlayerStream[8746:47938] 80: Failed to set processVolumeScalar on device. Error: 560947818
2019-09-21 15:40:07.859455+0800 SampleAVPlayerStream[8746:47938] TIC SSL Trust Error [1:0x6000017fb480]: 3:0
2019-09-21 15:40:07.877511+0800 SampleAVPlayerStream[8746:47938] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
2019-09-21 15:40:07.881312+0800 SampleAVPlayerStream[8746:47938] Task <8F036D25-D6CC-433E-A61E-CD5A844CFAF5>.<1> HTTP load failed (error code: -1202 [3:-9813])
2019-09-21 15:40:07.886919+0800 SampleAVPlayerStream[8746:47938] Task <8F036D25-D6CC-433E-A61E-CD5A844CFAF5>.<1> finished with error - code: -1202
2019-09-21 15:40:07.900192+0800 SampleAVPlayerStream[8746:48024] Task <8F036D25-D6CC-433E-A61E-CD5A844CFAF5>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “192.168.0.27” which could put your confidential information at risk." UserInfo={NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, NSErrorPeerCertificateChainKey=(
    "<cert(0x7fc32a084600) s: Gus Fakelastname i: Gus Fakelastname>"
), NSErrorClientCertificateStateKey=0, NSErrorFailingURLKey=https://192.168.0.27:8080/Videos/heyheyhey.mp4, NSErrorFailingURLStringKey=https://192.168.0.27:8080/Videos/heyheyhey.mp4, NSUnderlyingError=0x600002c9c4b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1202 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x6000010e8750>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9813, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9813, kCFStreamPropertySSLPeerCertificates=(
    "<cert(0x7fc32a084600) s: Gus Fakelastname i: Gus Fakelastname>"
)}}, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <8F036D25-D6CC-433E-A61E-CD5A844CFAF5>.<1>"
), _kCFStreamErrorCodeKey=-9813, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <8F036D25-D6CC-433E-A61E-CD5A844CFAF5>.<1>, NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x6000010e8750>, NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “192.168.0.27” which could put your confidential information at risk.} [-1202]

更新:如果我将服务器恢复为http

,则为日志
    2019-09-21 19:12:37.829817+0800 SampleAVPlayerStream[4270:23381] Task <D17E6DB2-73F5-4C8D-92B7-A10B0EECD8BD>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=http://192.168.0.27:8080/Videos/heyheyhey.mp4, NSErrorFailingURLKey=http://192.168.0.27:8080/Videos/heyheyhey.mp4, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <D17E6DB2-73F5-4C8D-92B7-A10B0EECD8BD>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <D17E6DB2-73F5-4C8D-92B7-A10B0EECD8BD>.<1>, NSLocalizedDescription=cancelled} [-999]
2019-09-21 19:12:37.826346+0800 SampleAVPlayerStream[4270:23254] Task <D17E6DB2-73F5-4C8D-92B7-A10B0EECD8BD>.<1> finished with error - code: -999

这是Swift代码。

if let urlVal = NSURL(string: "https://192.168.0.27:8080/Videos/heyheyhey.mp4") {
        let player = AVPlayer(url: urlVal as URL);
        let vc = AVPlayerViewController();
        vc.player = player;

        present(vc, animated: true) {
            vc.player?.play();
        }
    }

0 个答案:

没有答案
相关问题