Neither I don't want to mute or unmutes iPhone nor I want to detect that it muted or unmuted, I just want to know, how can I detect mute button trigger event whether it is on to off or off to on?
There is no native iOS API to detect if the mute switch is enabled/disabled on a device.
The general principle to check if the device is muted is to play a short sound and detect the length it took to play. From this length, we can determine if it was muted or not. Check https://github.com/akramhussein/Mute or https://github.com/moshegottlieb/SoundSwitch
Related
I'm building a VoIP app on iOS and I'm using the AVAudioSession category of AVAudioSessionCategoryPlayAndRecord, which is recommended for VoIP apps that need to constantly play and record audio.
However, when the user switches their iPhone ringer to silent mode, the VoIP application will still play sound for an incoming call. This is not desired behavior.
Is there a way to prevent the incoming calls from playing audio when the user has their phone on silent, but still allow them to answer the call and have audio resume?
If you take a look here at the docs for AVAudioSession Categories, you can see that AVAudioSessionCategoryPlayAndRecord unfortunately does not obey the silencing of a phone, as seen below:
Your audio continues with the Silent switch set to silent and with the screen locked. (The switch is called the Ring/Silent switch on iPhone.)
If you want the audio to stop when you turn the phone to silent, you should use AVAudioSessionCategoryAmbient.
I think I found a solution that works for a VoIP application. If the phone is set to silent, I wanted the phone to show an alert and vibrate instead of playing the audible ring.
I can solve this by using local notifications and moving the sound out of the application and adding it to the notification itself. By specifying a sound file as part of the notification, iOS will handle whether it should play the audio or vibrate the phone. This is determined by the position of the Ring/Silent switch on the side of the phone.
Here's an Apple article on adding a sound to a local notification.
How to mute application sound when hardware mute button on iPhone and iPad is on.I want to detect that whenever hardware mute button is turned on and off my application sound will be turned on and off.
You need not listen to the event, just use appropriate audio session category.
AVAudioSessionCategoryAmbient or AVAudioSessionCategorySoloAmbient
I am working on a VOIP app on iOS. I have encountered some problems when implementing "Ignore incoming ringer" feature. It has the following requirements:
1. Should stop ringer if pressed screen lock or volume button
2. Should stop ringer if mute button is pushed to "mute" state
3. Should not play ringer if mute button is in "mute" state
Since iOS SDK provide no information of the phone's hardware buttons, I can only rely on setting AVAudioSession category. Before playing ringer, I set the category to ambient so screen lock and mute button can stop the audio. But this method cannot satisfy my requirements because app cannot play ringer when in background because ambient category cannot support background audio.
In order to solve this problem, I start playing the ringer in playbackandrecord category to make the audio stream come out and change the category to ambient immediately. Though it can meet my requirements, but this method caused many problems and bugs. For exameple, MPVolumeView cannot display the output devices correctly.
Can anyone provide a more elegant way way to simulate ringer? Or can this be done in iPhone? Since it will be in app store, I cannot use private apis. Thanks in advance.
There seem to be a few threads floating around this topic but no definitive answer: if a user loads the app with sound enabled but later mutes his/her iPhone, how can we detect this in PhoneGap? Is there a callback for this event? The docs don't seem to list anything.
A second, related question: how to detect the status of the mute button? If someone has mute enabled, how do you detect this to avoid playing audio? The media.play() method only seems to have an option concerning whether to play audio when the screen is locked.
Thanks!
I wanted our app to don't play sounds when the iPhone is muted.
After hours of searching I decided to try with the following parameter and works as expected:
myMedia.play({ playAudioWhenScreenIsLocked : false });
The documentation doesn't say anything that this parameter will make the sound to not play when the iPhone is muted, but it behaves like that.
I'm using PhoneGap 2.6.0 and the docs says:
Pass in this option to the play method to specify whether you want to
play the audio of the media file when the screen is locked (this
defaults to true if not set). If this is set to true, it will ignore
the state of the hardware mute button.
Bad documented?
I am working on an app that needs to pause and unpause the audio stream coming from the ipod app. Is there any way to do that? I want to make a button that once you press it, it pauses the currently playing song on the ipod app. Pressing it again unpauses where the music left off. I am also working on a way to change the volume of the ipod app, is there anyway to do this that does not rely on the user manually moving a slider?
Any help at all would be great. Thanks!
you could use this framework if you want: Media Player Framework
Specially the MPMusicPlayerController Class
You have this:
Controlling Playback
– play
– pause
– stop
Managing Playback Mode and State
volume ( property )