Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions ios/ReactNativeAudioToolkit/ReactNativeAudioToolkit/AudioPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down