Reputation: 13
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?
Upvotes: 1
Views: 2167
Reputation: 1933
Or your device just doesn't support the MediaPlayer Volume API.
From: Tips for XNA WP7 developers
Audio
· Never rely on sounds as your sole signal to the player that something is happening in the game. They might have the sound off. They might be playing somewhere loud. Etc.
· You have to provide controls to disable sound & music. These should be separate.
· On at least one model of phone, the volume control API currently has no effect. Players can adjust sound with their hardware volume buttons, but in game selectors simply won’t work. As such, it may not be worth the effort of providing anything beyond on/off switches for sound and music.
Upvotes: 0
Reputation: 11598
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.
Upvotes: 1