Plugin.Maui.Audio icon indicating copy to clipboard operation
Plugin.Maui.Audio copied to clipboard

Expecting audioManager.CreatePlayer to be synchroneous

Open jnthngdbt opened this issue 2 years ago • 1 comments

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

jnthngdbt avatar Apr 25 '23 18:04 jnthngdbt

Sorry it's been some time responding to this issue. Do you recall what platform you were seeing this on?

bijington avatar Nov 27 '23 22:11 bijington