Mute iOS microphone input with ReactNative - objective-c

I am using Agora's ReactNative library for a group calling project, I need the user to be able to mute/unmute his phone microphone. Currently there is only a function to muteLocalAudioStream which does mute the whole stream, that includes the background sounds, as the streamer can add background sound to the call.
For Android I managed to mute/unmute the microphone with the below hack:
#ReactMethod
public void muteMic(){
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
if (audioManager.isMicrophoneMute() == false) {
audioManager.setMicrophoneMute(true);
} else {
audioManager.setMicrophoneMute(false);
}
}
However, I couldn't do it for iOS, I appreciate your help on this.

You can change recording level with a call to
// volume: [0,100]
RtcEngine.adjustRecordingSignalVolume(volume)

Related

Receive "Siri remote" event in background on tvOS

I have made a radio player for tvOS and I wan't the audio stream to keep playing while in background. All this works nicely and was pretty easy.
However I would like to stop the stream/audio if "play/pause" button is pressed while in background. But I can't figure out how to do this.
I only want it to stop, not pause. This is how Apple Radio works.
I'm handling all my input with Press events and Actions, setup from the interface builder.
What I've found so far is how it works on iOS, and I've been suggested to use, but remoteControlReceivedWithEvent is never called (not even in foreground).
Any help on this is highly appreciated, especially if you've had the luck with implementing it yourself ;)
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
override func remoteControlReceivedWithEvent(event: UIEvent?) {}
thisI was able to get working using MediaPlayer's MPRemoteCommandCenter
func setupRemoteCommandCenter() {
let remoteCommandCenter = MPRemoteCommandCenter.sharedCommandCenter()
let pauseCommand = remoteCommandCenter.pauseCommand
pauseCommand.enabled = true
pauseCommand.addTarget(self, action: "pauseEvent")
}
func pauseEvent() {
pause()
}

AVCaptureDevice - iphone/ipad as video source

Can AVCaptureDevice be used (objective-c or Swift) to access an iOS device as a camera source, when it is connected via a lightning cable, very much like Quicktime does for OSX Yosemite?
Quicktime select camera source image
If not, is there any other way to capture it?
I'm using AVCaptureDevice.devices() (in swift) but it only lists the built-in Mac camera and mic.
Found the solution for this (thanks Chris Adamson), after looking at a presentation on WWDC where Apple announced this capability - fast forward to 4:09.
The following CMI property needs to be set before AVCaptureDevice can detect the iOS device as a camera/capture device (example in Swift):
var prop : CMIOObjectPropertyAddress = CMIOObjectPropertyAddress(
mSelector: CMIOObjectPropertySelector(kCMIOHardwarePropertyAllowScreenCaptureDevices),
mScope: CMIOObjectPropertyScope(kCMIOObjectPropertyScopeGlobal),
mElement: CMIOObjectPropertyElement(kCMIOObjectPropertyElementMaster))
var allow:UInt32 = 1
CMIOObjectSetPropertyData( CMIOObjectID(kCMIOObjectSystemObject),
&prop,
0,
nil,
UInt32(sizeofValue(allow)),
&allow)
After this is done (e.g. in your AppDelegate), the standard registration of observers can be done, and the iOS camera will show up in the list of available devices
// register for notifications when a new device is connected
notifications.registerObserver(AVCaptureSessionDidStartRunningNotification, forObject: session, block: {note in
var devices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeMuxed)
+ AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) as! [AVCaptureDevice]
for device in self.devices {
if device.modelID == "iOS Device" {
// device is your AVCaptureDevice... use it as usual
}
}
})

Is it possible to control the phone's vibrator?

I need to control the phone's vibration functionality when the user taps certain elements of my app's UI. I can't figure out how to get access the vibrator though. Is it possible? If so, how do I do this?
Yes it is possible - see Vibration Device class. This code should vibrate your phone:
private void Btn_Click(object sender, RoutedEventArgs e)
{
VibrationDevice device = VibrationDevice.GetDefault();
if (device != null) device.Vibrate(TimeSpan.FromSeconds(1));
}
The above code should work for WP8.1 WinRT, for WP8.1 Silverlight take a look here at MSDN and use VibrateController class.

Playing different Sound files in Appcelerator Titanium makes the audio got noise

I have created an app using appcelerator for Iphone , which buy click on buttons it will play a relative sound , here is the code, but the problem is when i play the audio many times and play different audios using this function the sound starts to lag and have noise inside, can anybody help me with it , Thanks.
var soundplaying = 0;
var sound;
function playaudio(url) {
if (soundplaying == 0) {
sound = Ti.Media.createSound({});
sound.setUrl('../assets/audio/' + url);
sound.addEventListener('complete', function() {
sound.release();
soundplaying = 0;
});
sound.play();
soundplaying = 1;
}
}
(i have tried to release the sound object after each time but still no use, I tried to createSound only once but seems the titanium dose not support changing url for Media.Sound) dynamically.
I could have solve this issue temporary , by changing the audio files format to .m4a (aac).
i was using mp3 earlier.

headphone plug-in plug-out event when audio route doesn't change - iOS

I'm working on iPad.
I would like to detect when user plug-out headphone. First I used a listener on the property kAudioSessionProperty_AudioRouteChange. So all was working well until I've decided to add a button to switch to speakers when headphone was still plugged. So I’m now facing a problem, maybe someone would have an idea to fix it.
Here is the scenario :
I plug a headphone -> my audio route change callback is called
then I switch sound to speakers (without unplugging my headphone) -> audio route change callback is called
then I unplug my headphone (when sound is still outputting to speakers) -> audio route change callback is NOT called, which seems logical.
But here is my problem ! So my question is : Do you see a way to detect that headphone was unplugged for this last case ?
Thanks for your help
EDIT :
Ok I found a workaround :
To detect whether or not headphones are plugged, I execute a test function all the times I need to know it (instead using a boolean), this might be less good for performances but it's working, here is my code for the ones who may need it :
//set back the default audio route
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);
//check if this default audio route is Heaphone or Speaker
CFStringRef newAudioRoute;
UInt32 newAudioRouteSize = sizeof(newAudioRoute);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &newAudioRouteSize, &newAudioRoute);
NSString *newAudioRouteString = (__bridge NSString *)newAudioRoute;
CFRelease(newAudioRoute);
//if this default audio route is not Headphone, it means no headphone is plugged
if ([newAudioRouteString rangeOfString:#"Headphones"].location != NSNotFound){
NSLog(#"Earphone available");
return true;
}
else {
NSLog(#"No Earphone available");
return false;
}
Hope it will help someone !
I imagine a solution it in the following way:
You create in the AppDelegate a boolean for the speakers, let's say:
BOOL isSpeakerOn. And every time the audio route callback is called you have to verify what the current situation with the speakers and what you want to do then.
This is the best tutorial dealing this issue:
http://www.techotopia.com/index.php/Detecting_when_an_iPhone_Headphone_or_Docking_Connector_is_Unplugged_(iOS_4)