Search code examples
c#media-playerwindows-phone-7.1

Can't Set MediaPlayer.Volume


I'm investigating different methods for controlling volume and I can't seem to set MediaPlayer.Volume in my Windows Phone 7.1 application. Basically, calling

MediaPlayer.Volume = value;

has no effect, and calling MediaPlayer.IsMuted = TRUE has no effect.

Example:

public MainPage()
{
    InitializeComponent();
    //Play a song from the collection
    FrameworkDispatcher.Update(); 
    MediaPlayer.Play(ml.Artists[0].Songs[0]);
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    //Reduce volume to 0
    FrameworkDispatcher.Update(); 
    MediaPlayer.Volume = 0.0f;
    //If I set a breakpoint here, MediaPlayer.Volume is 1.0
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    //This also has no effect...
    FrameworkDispatcher.Update(); 
    MediaPlayer.IsMuted = !MediaPlayer.IsMuted;
}

Does anyone know what simple obvious fact that I am misunderstanding?


Solution

  • I'm not familiar with MediaPlayer, but it looks like you are no longer allowed to set the Volume and and Muted properties when playing from the Zune library. Changes in XNA Studio 4.0

    I assume that your ml variable refers to a Zune media library and that is why you have this problem. If you stop playing the song, and then adjust the volume, or adjust the volume beforehand, then the issue should go away.

    You also might take a look at MediaElement and see if it is appropriate to your scenario.