florent37 / Flutter-AssetsAudioPlayer

Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
https://pub.dartlang.org/packages/assets_audio_player
Apache License 2.0
743 stars 337 forks source link

currentPosition more precise / in milliseconds #513

Open TorstenFH opened 3 years ago

TorstenFH commented 3 years ago

Is there a possibility to receive currentPosition in milliseconds?

I am developing an app for the playback of music in interaction with music sheet. For a visual metronome on the music sheet, I need the position to be more precise than in seconds.

Right now I'm using:

StreamBuilder(
                        stream: assetsAudioPlayer.realtimePlayingInfos,
                        builder: (context, snapshot) {
                          final snapshotData = snapshot.data;
                          final currentPosition = snapshotData.currentPosition;
                          return Stack(
                            children: buildNoteSheetWithDots(
                                noteDots: noteDots, position: currentPosition),
                          );
                        },
                      )
kalismeras61 commented 3 years ago

@TorstenFH you can get easily with below

snapshotData.currentPosition.inMilliseconds

TorstenFH commented 3 years ago

@TorstenFH you can get easily with below

snapshotData.currentPosition.inMilliseconds

Thanks kalismeras62! I have also tested this, but it seems that I only get a very inaccurate value (seconds?), which is then converted into milliseconds.

On iOS (iPhone XR): flutter: Stream in ms: 0 flutter: Stream in ms: 172 flutter: Stream in ms: 472 flutter: Stream in ms: 772 flutter: Stream in ms: 1072 flutter: Stream in ms: 1372 flutter: Stream in ms: 1672 flutter: Stream in ms: 1972 flutter: Stream in ms: 2272 flutter: Stream in ms: 2572 flutter: Stream in ms: 2872 flutter: Stream in ms: 3171 flutter: Stream in ms: 3472 flutter: Stream in ms: 3772 flutter: Stream in ms: 4072 flutter: Stream in ms: 4372 flutter: Stream in ms: 4672 flutter: Stream in ms: 4972 flutter: Stream in ms: 5272 flutter: Stream in ms: 5572 flutter: Stream in ms: 5872 flutter: Stream in ms: 6171 flutter: Stream in ms: 6472 flutter: Stream in ms: 6772 flutter: Stream in ms: 6772

On web (Chrome): Stream in ms: 0 Stream in ms: 0 Stream in ms: 159 Stream in ms: 366 Stream in ms: 571 Stream in ms: 772 Stream in ms: 992 Stream in ms: 1198 Stream in ms: 1400 Stream in ms: 1607 Stream in ms: 1811 Stream in ms: 2017 Stream in ms: 2220 Stream in ms: 2426 Stream in ms: 2632 Stream in ms: 2835 Stream in ms: 3042 Stream in ms: 3247 Stream in ms: 3451 Stream in ms: 3657 Stream in ms: 3860 Stream in ms: 4065 Stream in ms: 4270 Stream in ms: 4474 Stream in ms: 4678 Stream in ms: 4884 Stream in ms: 5086 Stream in ms: 5288 Stream in ms: 5490 Stream in ms: 5692 Stream in ms: 5896 Stream in ms: 6101 Stream in ms: 6302 Stream in ms: 6504 Stream in ms: 6707 Stream in ms: 6909 Stream in ms: 7113 Stream in ms: 7317