diff --git a/ios/ReactNativeAudioToolkit/ReactNativeAudioToolkit/AudioPlayer.m b/ios/ReactNativeAudioToolkit/ReactNativeAudioToolkit/AudioPlayer.m index a5b8732f..3e77e9a6 100644 --- a/ios/ReactNativeAudioToolkit/ReactNativeAudioToolkit/AudioPlayer.m +++ b/ios/ReactNativeAudioToolkit/ReactNativeAudioToolkit/AudioPlayer.m @@ -192,9 +192,32 @@ - (NSURL *)findUrlForPath:(NSString *)path { while (player.status == AVPlayerStatusUnknown) { [NSThread sleepForTimeInterval:0.01f]; } + + //make sure loadedTimeRanges is not null + while (player.currentItem.loadedTimeRanges.firstObject == nil){ + [NSThread sleepForTimeInterval:0.01f]; + } + + float version = [[[UIDevice currentDevice] systemVersion] floatValue]; + + //wait until 10 seconds are buffered then play + if (version >= 10.0) { + player.currentItem.preferredForwardBufferDuration = 500; + } + Float64 durationSeconds = 0; + while (durationSeconds < 10){ + NSValue *val = player.currentItem.loadedTimeRanges.firstObject; + CMTimeRange timeRange; + [val getValue:&timeRange]; + durationSeconds = CMTimeGetSeconds(timeRange.duration); + [NSThread sleepForTimeInterval:0.01f]; + } // Callback when ready / failed if (player.status == AVPlayerStatusReadyToPlay) { + if (version >= 10.0) { + player.automaticallyWaitsToMinimizeStalling = false; + } callback(@[[NSNull null]]); } else { NSDictionary* dict = [Helpers errObjWithCode:@"preparefail"