[just_audio_background] - not able to work with LockCachingAudioSource
Which API doesn't behave as documented, and how does it misbehave? I'm already using the just_audio plugin with the LockCachingAudioSource mechanism but recently I integrated the just_audio_background plugin, implementation for the Android side and IOS side I did it perfectly as the docs say But when I try to play audio with this setup(shown below screenshot) it gives me errors like that a platform player with a specific identifier already exists
Minimal reproduction project https://github.com/tp-coderbabu/just_audio_lockcaching_audiosource.git
To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:
- run the git project
- Provide two buttons 1st code is working as expected with the given example
- 2nd button not working as it contains the LockCachingAudioSource
- See errors
Error messages
E/flutter ( 4255): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Platform player 5d3c487a-bfe1-408b-9508-8bb0189d348e already exists, null, null, null)
E/flutter ( 4255): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
E/flutter ( 4255): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
E/flutter ( 4255): <asynchronous suspension>
E/flutter ( 4255): #2 MethodChannelJustAudio.init (package:just_audio_platform_interface/method_channel_just_audio.dart:13:5)
E/flutter ( 4255): <asynchronous suspension>
E/flutter ( 4255): #3 _PlayerAudioHandler._init (package:just_audio_background/just_audio_background.dart:353:20)
E/flutter ( 4255): <asynchronous suspension>
E/flutter ( 4255):
Expected behavior I guess it should work with LockCachingAudioSource too.
Screenshots
with this setup, it's not working
using this code as in the example app it's working fine
Desktop (please complete the following information):
- OS: MacOS Monterey 12.3
Smartphone (please complete the following information):
- Device: Pixel 6a
- OS: Android 10
- Device: iPhone 12 pro
- OS: IOS 15.2
Flutter SDK version
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.6, on macOS 12.3 21E230 darwin-x64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.80.2)
[✓] Connected device (4 available)
[✓] Network resources
• No issues found!
Additional context Not found any.
I'm closing this since there is no git repo for me to clone. (If you don't know what I'm referring to, it is because you did not follow the instructions for submitting a bug report.)
@ryanheise I have provided a git repo, Please take a look, and sorry for not following the instructions
You also deleted the steps to reproduce section.
@ryanheise there aren't any specific steps for reproduction, yet I'm adding it now with the other instructions, I hope all the instructions are fulfilled.
@ryanheise have you looked at the issue?
I have just reopened the issue, but no I have not gotten to it yet.
@tushar0518 I noticed that calling
player.setAudioSource() without calling audioSource.request() throws this error. I had a similar issue.
Test device was: Google Pixel 7 pro.
This is a snippet of my entire method
Future<void> startPlayingAudio(Track? track) async {
try {
final thumbnail = audioTeachings
.firstWhereOrNull((element) => element.id == track?.albumId)
?.thumbnail;
var audioSource = LockCachingAudioSource(
Uri.parse(track?.url ?? ""),
tag: MediaItem(
// Specify a unique ID for each media item:
id: track?.id ?? "0",
// Metadata to display in the notification:
title: track?.title ?? "",
),
cacheFile: File(thumbnail ??
'${(await getTemporaryDirectory()).path}/cache/${Uri.parse(track?.url ?? "").pathSegments.last}'),
);
audioSource.request();
// Load and play the audio source
await audioPlayer.setAudioSource(
audioSource,
initialPosition: Duration.zero,
);
} catch (e) {
// Handle error, such as displaying a message to the user
}
}