Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
591 views
in Technique[技术] by (71.8m points)

ipad - Changing the volume without a volume slider on an iphone

I need your help. How should I proceed to change the sound volume in my app. I don't want to use a volume slider. Instead I have an UIImageView which is a volume knob, in which I rotate clockwise to increase, and anti clockwise to decrease the sound volume. The rotation is just an animation and I've already done that part.

I need your help and advice on how to increase/decrease the volume. Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I view this as a bug in Apple's code and have reported it to them both with Bug Reports and in person, but since they insist its a feature, you might as well benefit from it.

Use the following code to change your application's volume:

[[MPMusicPlayerController applicationMusicPlayer] setVolume:newVolume];

This will only work after you have established your audio session, either by playing a sound or by setting it active as such:

[[AVAudioSession sharedInstance] setActive:YES error:NULL];

Note as that you'll need MediaPlayer.framework and AVFoundation.framework and that the volume is between 0.0 and 1.0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...