iOS Question Disable the Voice of take picture ?

Discussion in 'iOS Questions' started by little3399, Jun 11, 2015.

  1. little3399

    little3399 Active Member Licensed User

    HI,
    Is there exist method to disable the voice of take picture by code ? Tks!
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Are you using LLCamera or Camera?
     
  3. little3399

    little3399 Active Member Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

    Which one are you using?
     
  5. little3399

    little3399 Active Member Licensed User

    LLCamera
     
  6. Erel

    Erel Administrator Staff Member Licensed User

  7. JackKirk

    JackKirk Active Member Licensed 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...
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    You can use this code with:

    Code:
    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
     
  9. JackKirk

    JackKirk Active Member Licensed User

    Erel,

    That works!

    I have put together a little test rig (to mute/unmute just rotate the phone between portrait and landscape):
    Code:
    '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: Mar 26, 2016
  10. JackKirk

    JackKirk Active Member Licensed 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: Mar 27, 2016
  11. narek adonts

    narek adonts Well-Known Member Licensed User

    Why dont you use the LLCamera_Preview event to not have shutter sound?

    Code:
    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
     
  12. JackKirk

    JackKirk Active Member Licensed User

  13. JackKirk

    JackKirk Active Member Licensed User

    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: Mar 28, 2016
  14. JackKirk

    JackKirk Active Member Licensed User

    Last edited: Mar 28, 2016
Loading...