flutter_sound
flutter_sound copied to clipboard
[HELP]:Cache size increases every time mPlayer!.startPlayer fromDataBuffer is called
// any mp3 buffer
mPlayer!.startPlayer(
fromDataBuffer: buffer,
codec: Codec.mp3,
);
Are there any ways to deal with this cache "leak"
I have tried to clear cache programmatically by doing this.
import 'package:path_provider/path_provider.dart';
//then
final cacheDir = await getTemporaryDirectory();
if (cacheDir.existsSync()) {
cacheDir.deleteSync(recursive: true);
}
but after doing so and running the startPlayer method I get the following error
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(ERR_UNKNOWN, ERR_UNKNOWN, startPlayer() error, null)
E/flutter ( 8375): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 8375): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter ( 8375): <asynchronous suspension>
E/flutter ( 8375): #2 MethodChannelFlutterSoundPlayer.invokeMethod (package:flutter_sound_platform_interface/method_channel_flutter_sound_player.dart:157:12)
E/flutter ( 8375): <asynchronous suspension>
E/flutter ( 8375): #3 FlutterSoundPlayer._startPlayer (package:flutter_sound/public/flutter_sound_player.dart:810:19)
E/flutter ( 8375): <asynchronous suspension>
E/flutter ( 8375): #4 FlutterSoundPlayer.startPlayer.<anonymous closure> (package:flutter_sound/public/flutter_sound_player.dart:750:11)
E/flutter ( 8375): <asynchronous suspension>
E/flutter ( 8375): #5 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:33:16)
E/flutter ( 8375): <asynchronous suspension>
E/flutter ( 8375): #6 FlutterSoundPlayer.startPlayer (package:flutter_sound/public/flutter_sound_player.dart:749:5)
Hi Chang. How are you doing? This is probably a bug in Flutter Sound. I am going to fix that this week.
iOS or Android or both? Which codec?
Cheers my friend.
noticed on android not sure how to check cache size on iOS will get my wife's phone tonight. codec is mp3 flutter_sound 9.1.3
Found a workaround. Use the following function to "copy" the asset to cacheDir then use fromURI
Future<File> assetToFile(String path) async {
final byteData = await rootBundle.load('assets/$path');
var tempDir = (await getTemporaryDirectory()).path;
final file = File('$tempDir/$path');
await file.writeAsBytes(byteData.buffer
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
return file;
}
// then call mPlayer!.startPlayer(fromURI:...)
I found the bug, and fixed it. I will try to generate 9.1.4 tomorrow
thanks
On Tue, Mar 1, 2022, 3:34 AM Larpoux @.***> wrote:
I found the bug, and fixed it. I will try to generate 9.1.4 tomorrow
— Reply to this email directly, view it on GitHub https://github.com/Canardoux/flutter_sound/issues/847#issuecomment-1054593860, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6OPL4VUL65IQUJADOAMB3U5PE5NANCNFSM5PO4ODSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you authored the thread.Message ID: @.***>
Hi @changcw83 , Flutter Sound 9.1.5 is released. The Files leak is fixed.
This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.