Allow seekTo to go to millisecond rather than floored second#321
Allow seekTo to go to millisecond rather than floored second#321mattbajorek wants to merge 1 commit into
Conversation
|
You are my life saver!! |
b3b41c5 to
c66e5a7
Compare
|
@ujas-m-simformsolutions could you rereview this one? I updated the merge conflict. |
There was a problem hiding this comment.
Pull Request Overview
Fixes iOS audio player seeking precision by preserving millisecond accuracy when converting seek time from milliseconds to seconds.
- Changes integer division order to prevent precision loss from integer truncation
- Converts millisecond timestamp to TimeInterval for more accurate seeking
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| func seekTo(_ time: Int?, _ result: @escaping FlutterResult) { | ||
| if(time != nil) { | ||
| player?.currentTime = Double(time! / 1000) | ||
| player?.currentTime = TimeInterval(time! / 1000) |
There was a problem hiding this comment.
The integer division time! / 1000 still occurs before the TimeInterval conversion, which means millisecond precision is still lost due to integer truncation. Convert to TimeInterval first, then divide: player?.currentTime = TimeInterval(time!) / 1000.0
| player?.currentTime = TimeInterval(time! / 1000) | |
| player?.currentTime = TimeInterval(time!) / 1000.0 |
| func seekTo(_ time: Int?, _ result: @escaping FlutterResult) { | ||
| if(time != nil) { | ||
| player?.currentTime = Double(time! / 1000) | ||
| player?.currentTime = TimeInterval(time! / 1000) |
There was a problem hiding this comment.
This doesn't change the behavior. TimeInterval is just a typealias for Double, so this is the same as the original Double(time! / 1000).
The problem is time! / 1000 runs first as integer division (both are Int), so the milliseconds get truncated before the conversion. Seek still floors to the nearest second.
Cast first, then divide:
player?.currentTime = Double(time!) / 1000For time = 1500: current gives 1.0s, this gives 1.5s.
|
Thanks for the PR @mattbajorek! Could you address the inline comment and rebase the branch onto the latest main so it's up to date? Happy to re-review once that's done. |
Issue
Currently when seeking on iOS the seek time will go to the closest second. This is because the int is first divided by 1000 which floors it and then it is converted to a double.
Fix
First convert int then divide it by 1000 to convert it into seconds.