How to properly dispose of AudioPlayer and memory stream

20 hours ago 3
ARTICLE AD BOX

I wanted to test out this .NET MAUI package.

https://github.com/jfversluis/Plugin.Maui.Audio

But now I have an issue where if I keep playing the pokemon sounds I get an error of

"local reference table overflow (max=512)"

How do I properly dispose of the audio player and memory stream after the audio is done playing?

I need the solution to let me play audio whenever I tap(call) this function. And not worry about the reference overflow

var audioBytes = await this._client.GetByteArrayAsync(pokemonToTalk.Cries.CrySrc); MemoryStream memoryStream = new(audioBytes); this.PlayAutioAsync(memoryStream); await memoryStream.DisposeAsync(); ------------------------------------------------------------------------- public void PlayAutioAsync(MemoryStream m) { var audioPlayer = audioManager.CreatePlayer(m); audioPlayer.Play(); }

To be clear about my project I want it to run the fetch every time my function runs since the user gets a new set of random pokemon after one is done talking.

If needed this is the pokemontotalk class:

public class PokemonDTO { [JsonPropertyName("name")] public string Name { get; set; } [JsonPropertyName("sprites")] public spritesDTO Sprites { get; set; } [JsonPropertyName("cries")] public CriesDTO Cries { get; set; } } public class spritesDTO { [JsonPropertyName("front_default")] public string FrontImgString { get; set; } [JsonPropertyName("back_default")] public string BackImgString { get; set; } } public class CriesDTO { [JsonPropertyName("latest")] public string CrySrc { get; set; } }
Read Entire Article