I wrote a custom Music player using the interface MediaPlayer and SongLibrary. However, when I try to change the volume of the music played, I cant hear the change in volume. I have used a slider as a volume control and wrote the following code to change the media volume:
The slider values are initialized as follows:
slider1.Minimum = 0; //maps to wp7 volume 0.0
slider1.Maximum = 10; //maps to wp7 colume 1.0
slider1.Value = 8; //maps to wp7 default volume 0.85
The volume change code is as follows:
private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
MediaPlayer.Volume = (float)((slider1.Value)/10.0);
}
Even if I hardcode the volume to 0, I can hear the music.
This is tested on WP7 SDKv7.1
Is this a bug in the SDK?
It is my understanding that this is a hardware bug with HTC WP7 devices. Volume will work correctly in the emulator as well as non-HTC phones.
There's three things to keep in mind when trying using the MediaPlayer.Volume property:
It doesn't work if you play a song from zune (stored in the Musique & Videos hub of the phone). Only for your app's custom musics.
You have to set the Volume property after starting the music. It will be ignored if you do it before
There's a few known bugs on the emulator. When it doesn't work, always try once on the device to make sure
Related
I'm attempting to mute the mic on my Logitech C920 webcam (OSX 10.8.5), but both implementations that I have tried do not work 100%. I would really appreciate it if someone who has experience with Apple's CoreAudio could take a look.
Here is what I have tried:
Setting mute via AudioObjectSetPropertyData() using:
address.mScope = kAudioDevicePropertyScopeInput;
address.mElement = kAudioObjectPropertyElementMaster;
address.mSelector = kAudioDevicePropertyMute;
This works, I can successfully mute/unmute but eventually I am able to get into a state where the mic is no longer receiving audio. It seems to be triggered by switching the default input to the internal mic while the C920 is in the muted state and switching back to the C920 mic. The only way that I have found to get the C920 mic back into a good state is to pull the USB cable and plug it back in.
Setting the volume to 0.0f via AudioObjectSetPropertyData() using:
address.mScope = kAudioDevicePropertyScopeInput;
address.mElement = kAudioObjectPropertyElementMaster;
address.mSelector = kAudioDevicePropertyVolumeScalar;
This almost works. The OSX UI input volume slider moves all the way to the left, but the mic is still picking up a little bit of audio. Uhhhhggg so close!
Opening the "Audio MIDI setup" app shows the C920 mic. When the volume value is set to zero, the dB value is 20. When the volume value is set to 1, the db value is set to 50. This is different from the built in mic that looks like it has a dB range of -12 to 12. Not sure if this matters.
When setting mute or the volume, I've tried fetching the individual channels and setting them as well. Doesn't seem to have an impact. I think with both input devices setting the Master channel is working fine.
I was wondering if maybe this is a hardware issue. I should note that the Logitech C920 isn't officially supported on the Mac (although a ton of people use it). I'm able to control the internal mic without any issues. Hopefully I'm just overlooking something :-)
When setting volume kAudioDevicePropertyVolumeScalar to zero. You should also set mute to true using kAudioDevicePropertyMute. When adjusting volume of inputs, be careful to check the mute status.
For example:
Adjust input volume in system audio panel to 0
Adjust input volume using kAudioDevicePropertyVolumeScalar to 100
Look at the db indicator, it stay at zero but the slider is in 100. No sound from microphone can be captured. Use kAudioDevicePropertyMute to get mute value, we can get mute = 1
Conclusion:
There is a "Mute" status for the input in the system, but no shown in the audio setting panel. System will auto set mute to true when adjust volume to zero and disable mute when set volume larger than zero.
I am almost done developing my first game for the Windows Phone 7 OS. Unfortunately, I've ran into a rather nasty problem. A simple task of just playing background music and a sound effect at the same time creates a serious distorsion in the sound effect play and the overall result is awful. This is when the sound comes out of the phone's speaker.
If, however, I use the headphones, all the problems go away (i.e., no distorsions whatsoever). I am also using the same code on an HTC HD7 and I don't see the problem either on the speaker or on the headphones.
The sound effect is an MP3 # 48kbps and the music is also an MP3 # 96 kbps.
All I do is the following:
In the LoadContent:
backgroundMusic = Content.Load<Song>("Music");
soundEffect = Content.Load<SoundEffect>("SoundEffect");
soundInst = soundEffect.CreateInstance(); / I am using a SoundEffectInstance to play the sound effect
MediaPlayer.Play(backgroundMusic);
MediaPlayer.IsRepeating = true;
Laster on, I just issue a soundInst.Play().
If, however, I do not play any music, the sound effect plays just fine.
Again, this only seems to happen on my Nokia Lumia 800 as it seems ok on the HTC HD7. However, the funny thing is that in the majority of the games that I play on the Lumia 800, I am not noticing this music/sound effect problem (I've only noticed it in one other game).
I have tried to play w/ the volume as well but it doesn't help. Even if the music has a volume of 0, the sound effect is not played correctly.
In conclusion, if and only if I stop the music from playing completly, regardless of the volume, the sound effect plays correctly.
Any ideas?
Thanks in advance!
I'm facing a very odd problem here, it seems like reducing or any action taken on the Volume property of the MediaPlayer static class doesn't make any difference. I've heard somewhere that microsoft protected it but it doesn't make any sense that in iPhone & Android you can do it, but in windows phone 7 it's impossible.
MediaPlayer.Volume = 0.2F;
what am i doing wrong?
Thanks!
You can't control the phone's global volume. Actually it makes difference, you just haven't notice it - it behaves as a scale for your music, so this goes like this:
System sound * MediaPlayer.Volume * What you are playing.
One does not simply look into MSDN: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.mediaplayer.volume.aspx
Are BackgroundAudioPlayer.Instance.Volume and the Volume n/30 that is displayed in the Universal Volume Control (mango only) connected?
I can set the BackgroundAudioPlayer.Instance.Volume value and whilst it does affect the Volume it does not change the n/30 figure in the UVC nor does it have the same level of control.
As an example setting BackgroundAudioPlayer.Instance.Volume to 1.0 (the max) is has a different level of sound when the UVC is 30/30 than when the UVC is 5/30.
What should I be setting in the app to mirror the UVC controls?
Can I request the UVC be displayed via code? (I realise it is displayed when u press the hardware volume buttons)
Pat
You can't affect the volume as displayed in the UVC. The phone's volume is up to the user to control.
The volume you can set for the BAP (and for MediaElement) is the relative volume within the app. In theory, setting the UVC volume to 30 and the BAP volume to 0.5 should be equivalent to setting the UVC volume to 15 and the BAP volume to 1.0.
Unless you want/need the volume of what you're playing via the BPA (or MediaElement) to be quieter relative to the other sounds on the phone always set the BAP volume to 1.0.
You control the relative volume of things within your app. The user controls the volume of the phone overall.
No, you can't trigger the UVC to be displayed from code.
I have an application using Nokia X2 which is 5 MPix camera. I need images only for 2 MPix. So I changed the settings on Phone to 2 MPix. When I take a snap by using Phones Camera application, I am getting a 2 MPix image. However, when I activate the camera through my J2ME Code, it gives me an image with 5 MPix. Any clue ?
You need to set the resolution for the camera through the API. It should look like something below.
cameraControl = (CameraControl)player.getControl("CameraControl");
cameraControl.setStillResolution(1)
You can read the supported resolutions with
int []res = cameraControl.getSupportedStillResolutions();
the the index of the returned array (res) is the value you set to CameraControl#setStillResolution()