Plugin.Maui.Audio
Plugin.Maui.Audio copied to clipboard
Expecting audioManager.CreatePlayer to be synchroneous
Hi,
Below is a code snippet where I load multiple mp3 tracks and create players for them. I expect the player to be ready after the call audioManager.CreatePlayer but it is somehow not (as observed when I print the duration which is always 0).
If I interact a bit later with the players, they do seem fully loaded and initialized. I interpret this as if audioManager.CreatePlayer was somehow having a async behavior that can't be awaited.
private async Task LoadAllTracks()
{
var nbTracks = tracks.Count;
for (int i = 0; i < nbTracks; ++i)
{
var trackData = await FileSystem.OpenAppPackageFileAsync(tracks[i].Filename);
var player = audioManager.CreatePlayer(trackData);
Trace.WriteLine($"Loaded track {i} with duration {player.Duration}");
allTrackPlayers.Add(player);
}
}
Am I doing something wrong? Is there a way to be sure when the player is fully initialized?
Thanks,
Jonathan
Sorry it's been some time responding to this issue. Do you recall what platform you were seeing this on?