Replies: 2 comments 3 replies
-
I Found the solution! This is my post. No Memory Leak At All: Map<String,AudioPlayer> audioPlayersMap1 = {}; // Map of String:audioplayers, to dispose each one personally by key
.................
break;
case 4:
switch (ext) {
case 1: _xtsn = 'WAV'; _aP = 'wavC/'; break; case 2: _xtsn = 'm4a'; _aP = 'm4aC/'; break;
case 3: _xtsn = ''; _aP = ''; break; case 4: _xtsn = 'mp3'; _aP = 'mp3C/'; break;
default: { _xtsn = 'WAV'; _aP = 'wavC/'; } break;
} //end switch
_kM = krSnd[_tI][_nI][_sOl].toString();
_nT = _aP + krSnd[_tI][_nI][_sOl] + '.' + _xtsn; // = we have got a ready path to sound file
if(audioPlayersMap4.containsKey(_kM)) {} else {
audioPlayersMap4.addEntries({_kM : AudioPlayer()}.entries); // adding AudioPlayer for absolutely new note
audioPlayersMap4 = Map.fromEntries(audioPlayersMap4.entries.toList()..sort((e1, e2) => e1.key.compareTo(e2.key))); // sorting HashMap
} //end if
audioPlayersMap4[_kM]?.setVolume(nVol); audioPlayersMap4[_kM]?.play(AssetSource('$_nT'), mode: PlayerMode.lowLatency);
setState((){countAmap=5;});
break;
case 5:
...........
/// JUST USE STOP() !!!!!!
audioPlayersMap[_kM]?.setVolume(nVol); await audioPlayersMap[_kM]?.stop();
await audioPlayersMap[_kM]?.play(AssetSource('$_nT'), mode: PlayerMode.lowLatency);
|
Beta Was this translation helpful? Give feedback.
3 replies
-
We will soon release AudioPool, where you can create a set players with the same sound. Hopefully it is not mess up the memory. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How would I describe the problem:
Each audio player can only play the file it currently captures (As if he wants to write something down there) and prevents another audio player from capturing it. Therefore, if you want to click on the button five times per second and hear the simultaneous sound of all sounds and the after sound from the previous ones, you need five new audio players (hash table key:audioPlayer()), each of which plays its own file, each from its own folder (each will be copied to a temporary directory if the filename is the same). The audio player will not give access to the file until its sound is completed. Or you will have to do MyTableOfAudioplayers[i].dispose() breaking off every unfinished sound to stop playback and return open access to the file to other audio players. The problem is caused by the lack of access to the still-sounding file (OS error: file is busy by another process).
The result is either a memory leak of more than 1 GB and a small folder with 60 MB of audio files, or no memory leak at all (only 120 MB of RAM), but with a lot of temporary folders (for example 60 MB * 10). I repeat, for two dozen notes, after two dozen playback cycles of several dozen notes each time (with the creation of new copies of the Audio Player), the memory leak will already be more than 1 GB
And you can’t do .dispose() during playback, otherwise - a red or gray screen (a serious mistake, almost a crash). Also, if you do not .dispose(), but do .release(), then the Audio Player will no longer get access to its file, even if you try to return it to it. We need to create a new copy of the audio player, adding it to our audioPlayers hash table. This is how I understand what's going on. If there is a way to allow multiple processes to read the same file without leaking memory, then that WOULD BE the BEST solution.
Beta Was this translation helpful? Give feedback.
All reactions