I am trying to make a game in flutter using flame (flame: ^1.30.1 flame_audio: ^2.11.11). I wanted to add sound effect, but this is where it goes wrong. When playing the game on an android emulator, the first few sounds are ok, but after a while they get noisy to the point where it stops completely and sometimes displays the sounds a minute later or so. I tried two different approaches, both with the same result.
aproach 1
I used flame audio and played the sound effect directly by specifying the path in the assets folder:
import 'package:flame_audio/flame_audio.dart';
FlameAudio.play('sound_effects/block_pickup.mp3');
FlameAudio.play('sound_effects/block_placing.mp3');
aproach 2
I used pools to load the audio and then play them from the pool:
import 'package:flame_audio/flame_audio.dart';
class PuzzleGameWorld extends World {
late AudioPool poolBlockPickup;
late AudioPool poolBlockPlacing;
Future onLoad() async {
// initialise audio pools
poolBlockPickup = await FlameAudio.createPool(
'sound_effects/block_pickup.mp3',
maxPlayers: 4,
);
poolBlockPlacing = await FlameAudio.createPool(
'sound_effects/block_placing.mp3',
maxPlayers: 4,
);
}
poolBlockPickup.start();
poolBlockPlacing.start();
In both cases I noticed this in the logs. I don't know if this is maybe causing the problem?
Background concurrent mark compact GC freed 7706KB AllocSpace bytes, 0(0B) LOS objects, 49% free, 7460KB/14MB, paused 196us,5.570ms total 29.703ms
I/m.example.basic(22759): Background concurrent mark compact GC freed 6834KB AllocSpace bytes, 0(0B) LOS objects, 49% free, 7850KB/15MB, paused 106us,5.400ms total 28.545ms
I/Choreographer(22759): Skipped 99 frames! The application may be doing too much work on its main thread.
I/Choreographer(22759): Skipped 112 frames! The application may be doing too much work on its main thread.