.NET MAUI native audio player

637 Views Asked by At

I am interested is there a way to play mp3 files from the phone internal memory using the built in native audio player. I am asking this, because I want to implement an equalizer too, so I am guessing I will have to work with streams.

I know for the MediaPlayer, and the Plugin.Maui.Audio, but I don't know how could I integrate the equalizer in the process.

Any nuget package that can be used as equalizer?

UPDATE:

Reading and search lead me to this plugin. I imported it to my project an tried to add an equalizer to the constructor. For test I wanted to adjust the frequency what I did at the end, but cant figure it out which band does what. Tried to read the documentation of the java implementation, but not got any smarter.

internal AudioPlayer(Stream audioStream)
{
    player ??= new MediaPlayer();
    player.Completion += OnPlaybackEnded;

    if (OperatingSystem.IsAndroidVersionAtLeast(23))
    {
        stream = new MemoryStream();
        audioStream.CopyTo(stream);
        var mediaDataSource = new StreamMediaDataSource(stream);

        equalizer ??= new Equalizer(0, player.AudioSessionId);
        equalizer.SetEnabled(true);

        //what am I setting here, because this works the sound changed ???
        //equalizer.SetBandLevel(0, -1000);
        //equalizer.SetBandLevel(1, -500);
        //equalizer.SetBandLevel(2, -250);
        //equalizer.SetBandLevel(3, 500);
        //equalizer.SetBandLevel(4, 1000);

        player.SetDataSource(mediaDataSource);
        player.Prepare();
    }
    else
    {
        PreparePlayerLegacy(audioStream);
  

} }

1

There are 1 best solutions below

2
On

On Android, you can use the MediaPlayer class to play sound. The MediaPlayer class can play audio and video files, and it provides a rich set of features such as seeking, looping, and volume control.

On iOS, you can use the AVFoundation framework to play sound. The AVFoundation framework provides classes for playing, recording, and editing audio and video. To play a sound on iOS, you can use the AVPlayer class.

About using the Equalizer you can check that if the MediaPlayer and AVFoundation support the equalizer. MediaPlayer has the Equalizer you can refer to Equalizer for MediaPlayer for more information.