【问题标题】:AVPlayer plays HLS but crashes with MP4 videoAVPlayer 播放 HLS 但与 MP4 视频崩溃
【发布时间】:2017-04-28 18:49:31
【问题描述】:

AVPlayers 播放 HLS,但在播放 MP4 视频时崩溃。我正在使用以下网址;我还在使用 IMA SDK for iOS 播放广告,它与第一个 URL 完美配合,但应用程序在没有播放广告的情况下与第二个 URL 一起崩溃。

使用 iOS 版本:10.1

//NSString *const kTestAppContentUrl_MP4 = @"http://50.7.149.90:1935/pitvlive/ptvsportsnew3.stream/playlist.m3u8";

NSString *const kTestAppContentUrl_MP4 = @"http://50.7.149.74/vods/trailers/OK Jaanu-Official Trailer.mp4";


> *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid number value (NaN) in JSON write'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001076b634b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010aba621e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010771f265 +[NSException raise:format:] + 197
    3   Foundation                          0x000000010a6efbfe _writeJSONNumber + 302
    4   Foundation                          0x000000010a69a138 _writeJSONValue + 480
    5   Foundation                          0x000000010a6efa12 ___writeJSONObject_block_invoke + 226
    6   CoreFoundation                      0x0000000107646e55 __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 85
    7   CoreFoundation                      0x0000000107646d6a -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] + 250
    8   Foundation                          0x000000010a6ef806 _writeJSONObject + 430
    9   Foundation                          0x000000010a69a0dd _writeJSONValue + 389
    10  Foundation                          0x000000010a6efa12 ___writeJSONObject_block_invoke + 226
    11  CoreFoundation                      0x000000010763d9d6 __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 102
    12  CoreFoundation                      0x000000010763d8da -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 202
    13  Foundation                          0x000000010a6ef806 _writeJSONObject + 430
    14  Foundation                          0x000000010a69a0dd _writeJSONValue + 389
    15  Foundation                          0x000000010a699f04 -[_NSJSONWriter dataWithRootObject:options:error:] + 124
    16  Foundation                          0x000000010a699de4 +[NSJSONSerialization dataWithJSONObject:options:error:] + 333
    17  AVPlayer                            0x0000000106c552e4 -[IMAJavascriptDispatcher sendMessage:] + 313
    18  AVPlayer                            0x0000000106c55c5e -[IMAJavascriptSession sendMessage:] + 135
    19  AVPlayer                            0x0000000106c5f40d -[IMABaseManager sendMessage:data:] + 161
    20  AVPlayer                            0x0000000106c5dd1c -[IMABaseManager initializeWithAdsRenderingSettings:] + 1295
    21  AVPlayer                            0x0000000106c5d7f7 -[IMABaseManager initializeWithContentPlayhead:adsRenderingSettings:] + 100
    22  AVPlayer                            0x0000000106c5b336 -[IMAAdsManager initializeWithAdsRenderingSettings:] + 108
    23  AVPlayer                            0x0000000106c5173b -[ViewController adsLoader:adsLoadedWithData:] + 331
    24  AVPlayer                            0x0000000106c59e3f __39-[IMAAdsLoader handleMessageAdsLoaded:]_block_invoke + 94
    25  libdispatch.dylib                   0x000000010d3a9980 _dispatch_call_block_and_release + 12
    26  libdispatch.dylib                   0x000000010d3d30cd _dispatch_client_callout + 8
    27  libdispatch.dylib                   0x000000010d3b38d6 _dispatch_main_queue_callback_4CF + 406
    28  CoreFoundation                      0x000000010767a4f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    29  CoreFoundation                      0x000000010763ff8d __CFRunLoopRun + 2205
    30  CoreFoundation                      0x000000010763f494 CFRunLoopRunSpecific + 420
    31  GraphicsServices                    0x000000010ce2ca6f GSEventRunModal + 161
    32  UIKit                               0x0000000108778964 UIApplicationMain + 159
    33  AVPlayer                            0x0000000106c5215f main + 111
    34  libdyld.dylib                       0x000000010d41f68d start + 1
    35  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

【问题讨论】:

  • 在 AVPlayer 中播放独立 MP4 会怎样?我建议也尝试其他 MP4。

标签: avplayer ios10 avplayerviewcontroller imasdk


【解决方案1】:

网址中有一个空格,所以我使用某人的以下方法对网址进行编码。

- (NSString *) URLEncodedString_ch:(NSString*) str {
NSMutableString * output = [NSMutableString string];
const unsigned char * source = (const unsigned char *)[str UTF8String];
int sourceLen = strlen((const char *)source);
for (int i = 0; i < sourceLen; ++i) {
    const unsigned char thisChar = source[i];
    if (thisChar == ' '){
        [output appendString:@"+"];
    } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
               (thisChar >= 'a' && thisChar <= 'z') ||
               (thisChar >= 'A' && thisChar <= 'Z') ||
               (thisChar >= '0' && thisChar <= '9')) {
        [output appendFormat:@"%c", thisChar];
    } else {
        [output appendFormat:@"%%%02X", thisChar];
    }
}
return output;

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-19
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    相关资源
    最近更新 更多