Skip to content

Avalonia Android - Preferred Method for Playing WAV Files? #19448

Answered by msneijders
jjcakes asked this question in Q&A
Discussion options

You must be logged in to vote

some pseudocode:

// in a part for netx.0-android

using Android.Media;

SoundPool soundPool = new SoundPool.Builder().SetMaxStreams(2)!.Build()!; // do only once
int resid = 1;// resource id of your wav/aac file
int soundId = _soundPool.Load(global::Android.App.Application.Context, resid, 1); // loading is async, you must wait for it to be loaded before play, or preload before you play
//after loading, you can reuse it to play:
//you can use soundPool LoadCompleted event to check
soundPool.Play(soundId, volume, volume, 1, 0, 1f);

And aac (audio files) in your project:

project
  |_ Resources
    |_ raw
        - negative.acc //sound for negative feedback
        - positive.acc //and for po…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@jjcakes
Comment options

@msneijders
Comment options

Answer selected by jjcakes
@jjcakes
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants