-
Notifications
You must be signed in to change notification settings - Fork 225
Allow seekTo to go to millisecond rather than floored second #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,7 +129,7 @@ class AudioPlayer: NSObject, AVAudioPlayerDelegate { | |
|
|
||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| sendCurrentDuration() | ||
| result(true) | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The integer division
time! / 1000still 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.0There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattbajorek Please see this.