Copying this issue from the just_audio repo since it seems to be an issue with the windows plugin. The original issue is here.
Which API doesn't behave as documented, and how does it misbehave?
AudioPlayer's seek(null) method. Specifically, this line causes a crash due to bad variant access.
Minimal reproduction project
The example modified is example_radio.dart. The onPressed function of the play button has been modified to follow the play with a two second delay and then an await player.seek(null). This is the only change.
https://github.com/Fenekhu/just_audio_live_seek_issue/blob/607a89dc650036b5511cfbefa731b718f2bd746e/just_audio/example/lib/example_radio.dart#L150
To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:
- Wait for initial loading
- Press play button
- After loading, (two seconds after pressing play), the program exits when seek is called.
Error messages
This crash doesn't produce any error messages in the flutter log.
[just_audio_windows] Called play
[just_audio_windows] Called seek
Lost connection to device.
Exited.
Expected behavior
The livestream skips to the most recent available audio.
Screenshots
Desktop:
- OS: Windows 11 (10.0.22635)
Flutter SDK version
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.27.1, on Microsoft Windows [Version 10.0.22635.4655], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.13.0 Preview 2.1)
[√] VS Code (version 1.96.2)
[√] Connected device (1 available)
[√] Network resources
• No issues found!
Additional context
It may not be possible to do this easily, as many of the MediaPlayer and MediaPlaybackSession properties and methods return unhelpful values for trying to find the end of the stream, such as NaturalDuration which return max long, DownloadProgress which returns -1, GetBufferedRanges which returns nothing, and GetSeekableRanges which returns 0 to max long. That said, Position does seem to return something reasonable, so it may be possible to manually track the time since starting the stream and seek to that. I think this could even be done outside of the C++ code in Dart even, but I'm not sure.
I may try that as a workaround, as my use case is wanting the stream to automatically return to live after pausing and resuming. If there is another way of achieving that, please let me know.
At the very least, the crashing can be prevented by changing the condition in this line to position != nullptr && !position->IsNull().
Copying this issue from the just_audio repo since it seems to be an issue with the windows plugin. The original issue is here.
Which API doesn't behave as documented, and how does it misbehave?
AudioPlayer'sseek(null)method. Specifically, this line causes a crash due to bad variant access.Minimal reproduction project
The example modified is example_radio.dart. The onPressed function of the play button has been modified to follow the play with a two second delay and then an await player.seek(null). This is the only change.
https://github.com/Fenekhu/just_audio_live_seek_issue/blob/607a89dc650036b5511cfbefa731b718f2bd746e/just_audio/example/lib/example_radio.dart#L150
To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:
Error messages
This crash doesn't produce any error messages in the flutter log.
Expected behavior
The livestream skips to the most recent available audio.
Screenshots
Desktop:
Flutter SDK version
Additional context
It may not be possible to do this easily, as many of the
MediaPlayerandMediaPlaybackSessionproperties and methods return unhelpful values for trying to find the end of the stream, such asNaturalDurationwhich return max long,DownloadProgresswhich returns -1,GetBufferedRangeswhich returns nothing, andGetSeekableRangeswhich returns 0 to max long. That said,Positiondoes seem to return something reasonable, so it may be possible to manually track the time since starting the stream and seek to that. I think this could even be done outside of the C++ code in Dart even, but I'm not sure.I may try that as a workaround, as my use case is wanting the stream to automatically return to live after pausing and resuming. If there is another way of achieving that, please let me know.
At the very least, the crashing can be prevented by changing the condition in this line to
position != nullptr && !position->IsNull().