Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Play *.wav file on Android device

$
0
0

Hi All,

My below code works fine on Genymotion emulator but it doesn't work while I am debugging on the device (I can't hear any voice):

`[assembly: Dependency(typeof(AudioService))]
namespace Persevy.Android
{
public class AudioService : IAudio
{
    public AudioService() 
    {
        _medialPlayer = new MediaPlayer();
    }

    private MediaPlayer _medialPlayer;

    public bool PlayMusicFile(string fileName)
    {
        _medialPlayer.Reset();
        _medialPlayer = MediaPlayer.Create(global::Android.App.Application.Context, Resource.Raw.ding_persevy);
        _medialPlayer.Start();

        return true;
    }
    }
}`

and

`try
        {
            DependencyService.Get<IAudio>().PlayMusicFile(
                StaticData.PomoBreakEndMusicFile
            );
        }
        catch (NullReferenceException ex)
        {

        }`

I've also added a RECORD_AUDIO permission. What should I check else?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>