This question already has answers here:
How to change device Volume on iOS - not music volume
(9 answers)
How to change an iOS device volume programmatically?
(4 answers)
Closed 6 years ago.
I am trying to create an alarm app and I have noticed that apps like Sleep Cycle will set your volume to max right before the alarm goes off, even if you had the volume at very low.
I have tried using AVAudioPlayer and all I have seen with MPVolumeView is that the user must do it.
Is there any way I can turn it up without the user having to do it?
Thank you for your help.
If I could please get the code in swift
You just need to import MediaPlayer. You can do as follow:
import MediaPlayer
And to set the volume to maximum
(MPVolumeView().subviews.filter{NSStringFromClass($0.classForCoder) == "MPVolumeSlider"}.first as? UISlider)?.setValue(1, animated: false)
I am playing the sound in my App and sound still continue play even when App enter into background i want to control the Volume of that audio when it enter into background . Like in this APP example.I want audio volume remain maximum even user try to turn off the volume. I am unable to splve it can any one out there help me out.
if you are using AVAudioPlayer the just use AVAudioPlayer instance say player like this:
player.volume=1; //for maximum volume
This is AVAudioPlayer's volume, and in reply to your question that even if user minimizes volume of Iphone it should remain in full, then you should know that according to apple policies, there are things which have control for user only, this is what they call user privilege, your app can not control iphone volume,
and for controlling player volume (you don't need any effort if you talk about iphone volume) , i am little doubtful how you want to do this, i mean you must have some button or horizontal slider to achieve this, anyhow proceed with your logic with the delegate method
- (void)applicationDidEnterBackground:(UIApplication *)application
in your appdelegate class
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
AVAudioPlayer: How to Change the Playback Speed of Audio?
I want to control the speed of the audio played by AVAudioPlayer, So is it possible to control the speed of the audio from slider controller?
I got solution with the help of OpenAL only. With the help of SimpleAudioEngine n CDAudioManager I have done it. referance link : http://www.learn-cocos2d.com/api-ref/1.0/CocosDenshion/html/interface_simple_audio_engine.html
The scenario is that I start the recording at in my iphone app maybe by using AVAudioRecoder and when i have some input sound above certain threshold then i will do some thing. Is it possible to process the input audio while recoding??
Is there any way to know the input loudness in iPhone. Like what is the level of the loudness in numbers or if there is any other measure for that.
Look at AVFoundation, AVAudioRecorder and enable the property meteringEnabled to get threshold change callbacks.
I can snap a picture with the iPhone programmatically by calling [UIImagePickerController takePicture:], but when I do the iPhone plays a loud recording of a shutter click. When I google for how to turn off the click, I find advice to rename the sound file that the iPhone plays. It seems to me for my app to do that would lead to it being rejected from the App store for accessing system frameworks. Is there a programmatic way to shut off that sound? The nature of my app demands that the camera be silent.
I assume you have solved it since but your app supposed to fail on the Appstore validation as it doesn't comply with iOS Dev License agreement. See below:
Section 3.3.8: Any form of user or device data collection, or image,
picture or voice capture or recording (collectively "Recordings"), and
any form of data, content or information collection, processing,
maintenance, uploading, syncing, storage, transmission, sharing,
disclosure or use performed by, through or in connection with Your
Application must comply with all applicable privacy laws and
regulations as well as any related Program Requirements, including but
not limited to any notice or consent requirements. In particular, a
reasonably conspicuous audio, visual or other indicator must be
displayed to the user as part of the Application to indicate that a
Recording is taking place.
Not sure if you would want to do it...
The sound is there to let someone know a photo is being taken. The idea is to ensure privacy and safety of the public, especially children," something that Japan has already required of their snap-happy citizens
Japan and Korea already have laws that require this sound when taking pictures.
http://abcnews.go.com/Technology/story?id=6750825&page=1
excerpt:
"In Japan and Korea, Segan pointed out, in response to mounting reports of "underskirting," governments have passed laws similar to the one King proposes."
Renaming the sound file wouldn't be using a "private API"; it's simply not possible from within the sandbox (assuming you haven't broken out of the sandbox somehow).
However, on 4.0+, you can use AVCapture to take pictures instead. I'm not sure if AVCaptureStillImageOutput plays a shutter sound; a workaround is to use video frames.
I have to wonder what you mean by "the nature of my app" though. If you're trying to do some sort of live image processing, then video frames are a much better way to go in the first place. If you're trying to take pictures silently with the user's permission, then the user should be able to silence the shutter sound anyway. If you're trying to take pictures without the user's permission, you're probably violating some agreement with Apple.
For what it's worth, I was able to get this to work by using this code in the snapStillImage method of AVCapture framework using AVCaptureStillImageOutput. It works perfectly for me on iOS 8.3 iPhone 5. I have also confirmed that Apple won't reject your app if you use this:
MPVolumeView* volumeView = [[MPVolumeView alloc] init];
//find the volumeSlider
UISlider* volumeViewSlider = nil;
for (UIView *view in [volumeView subviews]){
if ([view.class.description isEqualToString:#"MPVolumeSlider"]){
volumeViewSlider = (UISlider*)view;
break;
}
}
[volumeViewSlider setValue:0.0f animated:YES];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
Swift 4:
var volumeView = MPVolumeView()
//find the volumeSlider
var volumeViewSlider: UISlider? = nil
for view: UIView in volumeView.subviews {
if (view.self.description == "MPVolumeSlider") {
volumeViewSlider = view as? UISlider
break
}
}
volumeViewSlider?.setValue(0.0, animated: true)
volumeViewSlider?.sendActions(for: .touchUpInside)