How to play sounds on Xamarin.forms?

前端 未结 4 1744
星月不相逢
星月不相逢 2021-02-01 07:42

I\'m creating an app for Android, iOS and Windows Phone using Xamarin.forms. My question is how to play a mp3 or wav with Xamarin Forms?

My business logic is handled by

4条回答
  •  太阳男子
    2021-02-01 08:08

    You might give Xam.Plugin.SimpleAudioPlayer a try, since Xamarin.Forms doesn't have a sound API.

    In short, add the NuGet package to each platform-specific project you wish to support. Copy the audio files to the Assets folder for Windows UWP and Android and set the build actions as Content and Android Asset respectively. For iOS copy the audio files to the Resources folder and set the build action to BundleResource, then play the files like so:

    var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; 
    player.Load("intro_sound.mp3");
    player.Play();
    

提交回复
热议问题