AVPlayer воспроизводит HLS, но вылетает с видео MP4

AVPlayers воспроизводит HLS, но вылетает с видео MP4. Я использую следующие URL-адреса; Я также использую IMA SDK для iOS для воспроизведения рекламы, которая отлично работает с 1-м URL-адресом, но приложение вылетает со 2-м 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

person Kazmi    schedule 13.12.2016    source источник
comment
Что произойдет, если вы воспроизведете автономный MP4 в AVPlayer? Я бы порекомендовал попробовать и другие MP4.   -  person chauduyphanvu    schedule 15.12.2016


Ответы (1)


В URL-адресе был пробел, поэтому я использовал следующий метод для кодирования URL-адреса.

- (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;

}

person Kazmi    schedule 16.12.2016