Open rubenferreira97 opened 11 months ago
Which API doesn't behave as documented, and how does it misbehave? Calling
.stop
,.setAudioSource
and.play
too fast may cause issues.
Hi, the idea is to explain how it doesn't behave as "documented" which I'll include below:
/// When [preload] is `true`, this method may throw:
///
/// * [Exception] if no audio source has been previously set.
/// * [PlayerException] if the audio source was unable to be loaded.
/// * [PlayerInterruptedException] if another audio source was loaded before
/// this call completed or the player was stopped or disposed of before the
/// call completed.
I think the bug you might be getting at is that the expected behaviour is point 3 above, but the actual behaviour is an unhandled exception.
I think it is a bug because subsequent calls break completely the player. The players become unresponsive after the first crash with this exception: PlatformException(Platform player 7154b6f3-01e4-4a0c-897d-2be091c3b53a already exists, null, null, null)
Did you try the reproducible example?
I'm just trying to help you fill in the first section of the bug report. The exception is expected and actually right there in the documentation (which I'm saying you need to reference when filling in the first section), and hence the problem is not the exception, but rather that the exception is unhandled.
@ryanheise Sorry to bother, I edited my initial issue.
The exact same exceptions throw when preload = false
so I guess that's not documented. The player becomes broken afterwards, I still think this is a underlying issue. Even if an exception is thrown I think the player should not be in a inconsistent state.
The underlying problem "is" that the exception is unhandled, since that means that the exception isn't actually being thrown by the API that purports to throw that exception. if it were thrown, then it would be in the correct state, allowing you to set a new audio source etc.
I had the same issue, Any news here?
@firgia "I had the same issue, Any news here?" I had the same fault today, spent ages trying to find the cause, as a workaround I used different AudioPlayer();
same
The issue is still present, if anyone has any fix, do share.
The issue is reproducible by rapidly changing the audio sources and trying to play, but the issue is catching the error to fix it.
This issue is not fully resolved. I have fixed this issue by adding debounce at least 500ms and never see this issue anymore at the moment
This issue is not fully resolved. I have fixed this issue by adding debounce at least 500ms and never see this issue anymore at the moment
Can you share the code please ?
Can you share the code please ? @firgia
@Anshuman115 @kingrmb
import 'package:just_audio/just_audio.dart';
class JustAudioService {
static final JustAudioService _singleton = JustAudioService._internal();
factory JustAudioService() => _singleton;
JustAudioService._internal();
AudioPlayer audio = AudioPlayer();
Timer? _debounce;
Future<bool> play(String source) async {
Completer<bool> completer = Completer<bool>();
await stop();
bool isAlreadyPlay = false;
if (_debounce == null) {
isAlreadyPlay = true;
_playSource(source).then(
(value) {
if (!completer.isCompleted) completer.complete(value);
},
);
}
if (_debounce?.isActive ?? false) _debounce?.cancel();
_debounce = Timer(const Duration(milliseconds: 500), () async {
if (!isAlreadyPlay) {
_playSource(source).then(
(value) {
if (!completer.isCompleted) completer.complete(value);
},
);
}
_debounce = null;
});
return completer.future;
}
Future<bool> _playSource(String source) async {
try {
late AudioSource audioSource;
if (source.startsWith("http")) {
audioSource = LockCachingAudioSource(Uri.parse(source));
} else {
audioSource = AudioSource.file(source);
}
await audio.setAudioSource(audioSource);
await audio.play();
return true;
} catch (e) {
return false;
}
}
Future<void> stop() => audio.stop();
}
any complete solution to this ?
Which API doesn't behave as documented, and how does it misbehave? Calling
.setAudioSource
withpreload: false
throwsPlatformException
. However in the docs only states:Minimal reproduction project https://github.com/rubenferreira97/just_audio_bug
To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:
Error messages
Expected behavior Should switch audio and play it without crashes/exceptions.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Flutter SDK version
Additional context Add any other context about the problem here.