Skip to content

Commit

Permalink
feat: Adapt position update interval of darwin, linux, web (#1492)
Browse files Browse the repository at this point in the history
# Description

- Linux: changed update interval from `1000ms` to `250ms`
- Web: `position` was rounded to `1s` as its handed over as float, now
it's multiplied with `1000` to profit from millisecond precision, update
interval is still dependent on browser implementation
- Darwin: changed update interval from `0.2ms` to `200ms`, which most
probably was a mistake and caused much overhead
  • Loading branch information
Gustl22 authored May 7, 2023
1 parent c64ef6d commit ab5bdf6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,19 @@ Future<void> testStreamsTab(
}

extension StreamWidgetTester on WidgetTester {
// Precision for duration & position:
// Android: two tenth of a second
// Precision for position & duration:
// Android: millisecond
// Windows: millisecond
// Linux: second
// Web: second
// Linux: millisecond
// Web: millisecond
// Darwin: millisecond

// Update interval for duration & position:
// Android: two tenth of a second
// Update interval for position:
// Android: ~200ms
// Windows: ~250ms
// Linux: second
// Web: second
// Linux: ~250ms
// Web: ~250ms
// Darwin: ~200ms

Future<void> stopStream() async {
final st = StackTrace.current.toString();
Expand All @@ -144,7 +146,11 @@ extension StreamWidgetTester on WidgetTester {
await waitFor(
() async => expectWidgetHasDuration(
const Key('onDurationText'),
matcher: (Duration? actual) => durationRangeMatcher(actual, duration),
matcher: (Duration? actual) => durationRangeMatcher(
actual,
duration,
deviation: const Duration(milliseconds: 500),
),
),
timeout: timeout,
stackTrace: st,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class WrappedMediaPlayer {
self.url = url

// stream player position
let interval = toCMTime(millis: 0.2)
let interval = toCMTime(millis: 200)
let timeObserver = player.addPeriodicTimeObserver(forInterval: interval, queue: nil) {
[weak self] time in
self?.onTimeInterval(time: time)
Expand Down
4 changes: 2 additions & 2 deletions packages/audioplayers_linux/linux/audio_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ AudioPlayer::AudioPlayer(std::string playerId, FlMethodChannel *methodChannel,
if (panorama) {
audiobin = gst_bin_new(NULL);
audiosink = gst_element_factory_make("autoaudiosink", NULL);

gst_bin_add_many(GST_BIN(audiobin), panorama, audiosink, NULL);
gst_element_link(panorama, audiosink);

Expand All @@ -43,7 +43,7 @@ AudioPlayer::AudioPlayer(std::string playerId, FlMethodChannel *methodChannel,
gst_bus_add_watch(bus, (GstBusFunc)AudioPlayer::OnBusMessage, this);

// Refresh continuously to emit reoccurring events
_refreshId = g_timeout_add(1000, (GSourceFunc)AudioPlayer::OnRefresh, this);
_refreshId = g_timeout_add(250, (GSourceFunc)AudioPlayer::OnRefresh, this);
}

AudioPlayer::~AudioPlayer() {}
Expand Down
2 changes: 1 addition & 1 deletion packages/audioplayers_web/lib/num_extension.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extension NumExtension on num {
/// Converts [num] (expected in seconds) to the duration.
Duration fromSecondsToDuration() => Duration(
seconds: (isNaN || isInfinite ? 0 : this).round(),
milliseconds: ((isNaN || isInfinite ? 0 : this) * 1000).round(),
);
}

0 comments on commit ab5bdf6

Please sign in to comment.