4

I try to play a sound from a Raspberry Pi 3 with Raspbian installed. I have mono installed. I tested it on Windows, and it runs well. But when running it on Raspbian. I don't get any error message and no sound either.

public void PlaySound()
{
    try
    {
        using (var file = new FileStream("example.wav",
            FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            var player = new SoundPlayer(file);
            player.PlaySync();
        }
    }
    catch (Exception e)
    {
        Console.WriteLine("Sound failed to play");
    }
}

Mono version

Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-10)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS:           __thread
SIGSEGV:       normal
Notifications: epoll
Architecture:  armel,vfp+hard
Disabled:      none
Misc:          softdebug
LLVM:          supported, not enabled.
GC:            sgen
3
  • Have you checked that your Pi plays the wav file using something like omxplayer?
    – goobering
    Commented Feb 26, 2017 at 12:35
  • Yes I do, it works well with aplay or omxplayer Commented Feb 26, 2017 at 12:35
  • SoundPlayer is in System.Windows.Extensions.dll, which means that the class is unlikely to work properly on anything but windows. You can either spawn a process that runs omxplayer (or a similar app) or use a cross platform library such as NetCoreAudio. Commented Jan 18, 2021 at 4:10

1 Answer 1

0
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install mono-complete

or

sudo apt-get dist-upgrade

if your mono is already installed

This should fix the problem for SoundPlayer in RPI3

Not the answer you're looking for? Browse other questions tagged or ask your own question.