AVPlayer 抛出:“内部错误:重新启动太早”

问题描述 投票:0回答:3

我正在观察AVPlayer的KVO AVPlayerItemNewErrorLogEntryNotification,发现以下错误:

  • 错误状态代码:-12645 错误域:CoreMediaErrorDomain 错误注释:内部错误:重新启动太提前(-1.4084s)

我无法理解下面这行的真正含义。

“内部错误:重新启动时间过早”

谁能帮我找到这个问题的根本原因。

ios avplayer http-live-streaming avplayeritem
3个回答
12
投票

如果长 .ts 视频文件响应:-12645。

MPMovieErrorLogEvent 类中没有 MPMediaPlayer 返回的错误状态代码的文档。 但其中一些是:

HTTP status - errorStatusCode - errorDomain - errorComment

400     -12666  CoreMediaErrorDomain    unrecognized http response 400  
401     -12937  CoreMediaErrorDomain    Authentication Error    
402     -12666  CoreMediaErrorDomain    unrecognized http response 402  
403     -12660  CoreMediaErrorDomain    HTTP 403: Forbidden     
404     -12938  CoreMediaErrorDomain    HTTP 404: File not found    
405     -12666  CoreMediaErrorDomain    unrecognized http response 405  
406     -12666  CoreMediaErrorDomain    unrecognized http response 406  
407     -12937  CoreMediaErrorDomain    Authentication Error    
409     -12666  CoreMediaErrorDomain    unrecognized http response 409  
...                 
415     -12666  CoreMediaErrorDomain    unrecognized http response 415  

500     -12666  CoreMediaErrorDomain    unrecognized http response 500  
501     -12666  CoreMediaErrorDomain    unrecognized http response 501  
502     -12666  CoreMediaErrorDomain    unrecognized http response 502  
503     -12661  CoreMediaErrorDomain    HTTP 503: Unavailable   
504     -12666  CoreMediaErrorDomain    unrecognized http response 504  
505     -12666  CoreMediaErrorDomain    unrecognized http response 505  

if long .ts video file respons  -12645  CoreMediaErrorDomain    No response for media file in 10 s  

video .ts file bitrate differ from m3u8 declaration     -12318  CoreMediaErrorDomain    Segment exceeds specified bandwidth for variant     

for live stream.playlist m3u8 did not change too long   -12642  CoreMediaErrorDomain    Playlist File unchanged for 2 consecutive reads     

if wrong host ip    -1004   kCFErrorDomainCFNetwork     -   

if wrong dns host name  -1003   kCFErrorDomainCFNetwork     -   

if bad formatted URL    -1000   kCFErrorDomainCFNetwork     -   

if invalid https/ssl request    -1202   kCFErrorDomainCFNetwork     -

5
投票

据苹果员工称,此错误消息意味着:

玩家抱怨正在尝试重新启动直播, 但只有 1.4 秒的可用材料。有多少段 在你的现场播放列表中?这些天我们建议您始终在 播放列表中至少有六个片段。我相信唯一的效果是 延迟播放直到有足够的数据。

来源:https://forums.developer.apple.com/thread/40791


错误原因很可能源自m3u8本身。

流式传输直播节目(例如任何电视频道)时,事件数据的可用性与编码器创建媒体片段 (.ts)(然后附加到播放列表)之间存在延迟。

我可以想象,如果playerItem播放头的位置位于缓冲区的最边缘并且新媒体片段在服务器上的可用速度不够快,就会生成这些类型的错误。


这些错误是否应该在客户端预防或处理:

由于这些错误被报告为

internal
并且 AVPlayer 显然已从中恢复,因此可以安全地假设它们正在内部处理。因此,它们可以被理解为简单的错误报告,人们可以选择忽略它们。

如果想阻止它们,唯一的方法可能是手动将实时缓冲区的边缘及时设置为几秒。


0
投票

根据本杰明的回答以及我在 AVFoundation 的经验,您可以使用下面的代码将 AVPlayeritem 底层错误转换为 CoreMediaError 对于大多数常见情况。

public enum CoreMediaError:Error {
    
    static let domain = "CoreMediaErrorDomain"
    
    case unknown
    case notFound
    case unauthorized
    case authenticationError
    case forbidden
    case unavailable
    case mediaFileError
    case bandwidthExceeded
    case playlistUnchanged
    case decoderMalfunction
    case decoderTemporarilyUnavailable
    case wrongHostIP
    case wrongHostDNS
    case badURL
    case invalidRequest
    case unrecognizedHttpResponse
    
    init?(_ error:NSError){
        
        guard error.domain == CoreMediaError.domain else {return nil}
        
        switch error.code {
        case -12937:
            // HTTP: 401     -12937  CoreMediaErrorDomain    Authentication Error
            // HTTP: 407     -12937  CoreMediaErrorDomain    Authentication Error
            self = .authenticationError
        case -16840:
            self = .unauthorized
        case -12660:
            // HTTP: 403     -12660  CoreMediaErrorDomain    HTTP 403: Forbidden
            self = .forbidden
        case -12938:
            //HTTP: 404     -12938  CoreMediaErrorDomain    HTTP 404: File not found
            self = .notFound
        case -12661:
            //HTTP: 503     -12661  CoreMediaErrorDomain    HTTP 503: Unavailable
            self = .unavailable
        case -12645, -12889:
            //   if long .ts video file respons  -12645  CoreMediaErrorDomain    No response for media file in 10 s
            //   https://developer.apple.com/forums/thread/5589
            self = .mediaFileError
        case -12318:
            //  video .ts file bitrate differ from m3u8 declaration     -12318  CoreMediaErrorDomain    Segment exceeds specified bandwidth for variant
            self =  .bandwidthExceeded
        case -12642:
            //  for live stream.playlist m3u8 did not change too long   -12642  CoreMediaErrorDomain    Playlist File unchanged for 2 consecutive reads
            self =  .playlistUnchanged
        case -12911:
            self =  .decoderMalfunction
        case -12913:
            self =  .decoderTemporarilyUnavailable
        case -1004:
            //  if wrong host ip    -1004   kCFErrorDomainCFNetwork
            self =  .wrongHostIP
        case -1003:
            //   if wrong dns host name  -1003   kCFErrorDomainCFNetwork
            self =  .wrongHostDNS
        case -1000:
            //   if bad formatted URL    -1000   kCFErrorDomainCFNetwork
            self =  .badURL
        case -1202:
            //   if invalid https/ssl request    -1202   kCFErrorDomainCFNetwork
            self =  .invalidRequest
        case -12666:
            //400     -12666  CoreMediaErrorDomain    unrecognized http response 400
            //402     -12666  CoreMediaErrorDomain    unrecognized http response 402
            //405     -12666  CoreMediaErrorDomain    unrecognized http response 405
            //406     -12666  CoreMediaErrorDomain    unrecognized http response 406
            //409     -12666  CoreMediaErrorDomain    unrecognized http response 409
            //...
            //415     -12666  CoreMediaErrorDomain    unrecognized http response 415
            //500     -12666  CoreMediaErrorDomain    unrecognized http response 500
            //501     -12666  CoreMediaErrorDomain    unrecognized http response 501
            //502     -12666  CoreMediaErrorDomain    unrecognized http response 502
            //504     -12666  CoreMediaErrorDomain    unrecognized http response 504
            //505     -12666  CoreMediaErrorDomain    unrecognized http response 505
            self =  .unrecognizedHttpResponse
        default:
            self =  .unknown
        }
    }
}

您还可以查看this GitHub gist 了解更多详细信息

© www.soinside.com 2019 - 2024. All rights reserved.