Skip to content

Commit 555973f

Browse files
author
Robin Smith
committed
Prevent INFINITY value being written to JSON
Prevent the audio track playback percentage from being set to INFINITY if the track position appears to be INFINITY. This can happen before the track starts playing.
1 parent 86f15de commit 555973f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/ios/RmxAudioPlayer.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,12 @@ - (NSDictionary*) getPlayerStatusItem:(AudioTrack*)playerItem
10301030
NSDictionary* bufferInfo = [self getTrackBufferInfo:currentItem];
10311031
float position = [self getTrackCurrentTime:currentItem];
10321032
float duration = [bufferInfo[@"duration"] floatValue];
1033+
1034+
// Correct this value here, so that playbackPercent is not set to INFINITY
1035+
if (isnan(position) || isinf(position)) {
1036+
position = 0.0f;
1037+
}
1038+
10331039
float playbackPercent = duration > 0 ? (position / duration) * 100.0 : 0.0f;
10341040

10351041
NSString* status = @"";
@@ -1053,10 +1059,6 @@ - (NSDictionary*) getPlayerStatusItem:(AudioTrack*)playerItem
10531059
}
10541060
}
10551061

1056-
if (isnan(position) || isinf(position)) {
1057-
position = 0.0f;
1058-
}
1059-
10601062
NSDictionary *info = @{
10611063
@"trackId": currentItem.trackId,
10621064
@"isStream": currentItem.isStream ? @(1) : @(0),

0 commit comments

Comments
 (0)