Search code examples
c#audioaudio-channels

How to mute or select only one audio channel?


I'd know how can I mute or select only one audio channel in C#. I have to play an audio file only in the left/right channel. Is it possible? What do I have to do?


Solution

  • You will likely need to use the Balance property of System.Windows.Media.MediaPlayer.

    MSDN MediaPlayer Balance Property

    Set it to -1 for the left and 1 for the right channel.

        MediaPlayer mediaPlayer = new MediaPlayer();
    
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            mediaPlayer.Open(new Uri(@"C:\temp\Kalimba.mp3"));
    
            if (DateTime.Now.Second % 2 == 0)
            {
                mediaPlayer.Balance = 1;
                mediaPlayer.Play();
            }
            else
            {
                mediaPlayer.Balance = -1;
                mediaPlayer.Play();
            }
        }