iOS Question Disable the Voice of take picture ?

little3399

Active Member
Licensed User
Longtime User
HI,
Is there exist method to disable the voice of take picture by code ? Tks!
 

JackKirk

Well-Known Member
Licensed User
Longtime User
I have the same issue, this post seems to be suggesting that the sound volume can be muted/unmuted with a bit of Objective C:

http://stackoverflow.com/a/31640627

It could be a very useful tool in non-camera situations also.

Anyone with Objective C expertise interested?

Thanks...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code with:

B4X:
Sub Mute
 Dim no As NativeObject = Me 'should be inside a sub
 no.RunMethod("mute", Null)
End Sub

#if objc
@import MediaPlayer;
- (void) mute {
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;
  }
}
// mute it here:
[volumeViewSlider setValue:0.0f animated:YES];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
}
#end if
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Erel,

That works!

I have put together a little test rig (to mute/unmute just rotate the phone between portrait and landscape):
B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #Target: iPhone, iPad
    #MinVersion: 7
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private yn As Boolean
  
    Private xTTS As TTS

End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    'Initialize TTS
    xTTS.Initialize("")
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
  
    'Speak away
    xTTS.Stop
    xTTS.Speak("testing testing 1 2 3 4 5 6 7 8 9 10", True)

    yn=Not(yn)
    If yn Then
        Mute
    Else
        Unmute
    End If
  
End Sub

Private Sub Application_Background
  
End Sub

Sub Mute
Dim no As NativeObject = Me 'should be inside a sub
no.RunMethod("mute", Null)
End Sub

Sub Unmute
Dim no As NativeObject = Me 'should be inside a sub
no.RunMethod("unmute", Null)
End Sub

#if objc
@import MediaPlayer;
- (void) mute {
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;
  }
}
// mute it here:
[volumeViewSlider setValue:0.0f animated:YES];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
}
- (void) unmute {
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;
  }
}
// unmute it here:
[volumeViewSlider setValue:1.0f animated:YES];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
}
#end if

A couple of things:
  • I was able to work out how to unmute - but its pretty crude.
  • How to save the volume level before muting - so can restore?
  • How to reset volume level to previous level when unmuting?
  • How to stop the volume panel appearing when muting/unmuting?
Answers to these will solve the whole problem.

Thanks again...
 
Last edited:
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
For anyone interested...

Re the code in Erel's post #8:
  • As demonstrated in my post #9 - it works for muting/unmuting TTS - and I'm guessing music etc.
  • I incorporated it into an app that currently emits the camera shutter sound - it does not work.
  • I finally discovered that the volume of the camera shutter sound has nothing to do with "MPVolumeView" - it is actually controlled by the ringer volume.
  • To test: manually use the buttons on the top left of the phone to adjust ringer volume then use the camera app - the camera shutter sound volume is appropriately altered.
  • So, how to programmatically mute or minimize the ringer volume? - I googled a fair bit and only discovered this (or plagiarized copies):
  • Anyone with Objective C willing to have a go?
  • Also posts #7, 8 and 9 still have value - but in a different context - should I initiate a separate thread?
Regards...
 
Last edited:
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
For anyone interested...

Re the code in Erel's post #8:
  • As demonstrated in my post #9 - it works for muting/unmuting TTS - and I'm guessing music etc.
  • I incorporated it into an app that currently emits the camera shutter sound - it does not work.
  • I finally discovered that the volume of the camera shutter sound has nothing to do with "MPVolumeView" - it is actually controlled by the ringer volume.
  • To test: manually use the buttons on the top left of the phone to adjust ringer volume then use the camera app - the camera shutter sound volume is appropriately altered.
  • So, how to programmatically mute or minimize the ringer volume? - I googled a fair bit and only discovered this (or plagiarized copies):
http://stackoverflow.com/questions/...-the-ringer-or-change-the-ringer-tone-on-ios5
  • Anyone with Objective C willing to have a go?
  • Also posts #7, 8 and 9 still have value - but in a different context - should I initiate a separate thread?
Regards...
Why dont you use the LLCamera_Preview event to not have shutter sound?

B4X:
Dim ll as LLCamera

ll.Initialize(myPanel,"myCamera",True)
ll.StartPreview

Sub myCamera_Preview (Image As Bitmap)
  
    Dim myCapturedImage=Image
    ll.ReleaseFrame
    ll.StopPreview
  
End Sub
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Also posts #7, 8 and 9 still have value - but in a different context - should I initiate a separate thread?
Having got no response to this and in the meantime managing to solve the issues I raised in my post #9, I have put up a thread in iOS Code Snippets:

https://www.b4x.com/android/forum/threads/control-general-audio-volume.65118/

that allows you to programmatically control general audio volume.

Note that this offers no help to the issue in this thread which requires a means of programmatically controlling ringer/alerts volume - see my post #10 above.

Regards...
 
Last edited:
Upvote 0
Top