Android Question CameraEx - EnableShutterSound (no sound?)

yckhor

Member
Licensed User
Longtime User
Hi,
I am using CameraEx in my app and would like to enable shutter sound. Found the following sub to do it (posted by Erel).

Public Sub EnableShutterSound(Enabled As Boolean) As Boolean
r.target = nativeCam
Return r.RunMethod2("enableShutterSound", Enabled, "java.lang.boolean")
End Sub

It runs without any error messages on my Galaxy S4 but somehow, upon clicking on btnShutter button, a photo being taken but no shutter sound can be heard. I had called the EnableShutterSound(True) in my Camera_Ready() before CameraEx.CommitParameters. Am I placing it at the right location?

Thanks in anticipation.
 

yckhor

Member
Licensed User
Longtime User
Just checked.
Log("Enable Shutter Sound: " & CameraEx.EnableShutterSound(True))

The sub returned TRUE.
 
Upvote 0

yckhor

Member
Licensed User
Longtime User
Could this be a peculiar bug of Samsung Galaxy S4 variant of Android? Have been puzzling with some weird behaviours. Things that work fine in a rooted stock android 4.2.2 will behave differently in S4, also 4.2.2. By the way, I tried the bundled (samsung) camera app and it does make a shutter sound when I take a photo, but again, it could be using a WAV to mimic that instead of using enableShutterSound

I can bypass this playing a tiny WAV file but this may not be a resource-wise approach. Anyone tried on the same device, please share your findings.
 
Upvote 0

ComposerB4A

Member
Licensed User
Longtime User
Hi, i view the interesting post and tried this code and appear this error in log:
B4X:
** Activity (main) Resume **
cameraexclass_enableshuttersound (B4A line: 284)
Return r.RunMethod2("enableShutterSound", Enabled, "java.lang.boolean")
java.lang.NoSuchMethodException: enableShutterSound
    at java.lang.ClassCache.findMethodByName(ClassCache.java:278)
    at java.lang.Class.getDeclaredMethod(Class.java:762)
    at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:214)
    at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod2(Reflection.java:817)
    at anywheresoftware.b4a.samples.camera.cameraexclass._enableshuttersound(cameraexclass.java:270)
    at anywheresoftware.b4a.samples.camera.main._initializecamera(main.java:686)
    at anywheresoftware.b4a.samples.camera.main._activity_resume(main.java:340)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:538)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
    at anywheresoftware.b4a.samples.camera.main.afterFirstLayout(main.java:104)
    at anywheresoftware.b4a.samples.camera.main.access$100(main.java:16)
    at anywheresoftware.b4a.samples.camera.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:618)
    at android.os.Handler.dispatchMessage(Handler.java:123)
    at android.os.Looper.loop(SourceFile:351)
    at android.app.ActivityThread.main(ActivityThread.java:3814)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:538)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:659)
    at dalvik.system.NativeStart.main(Native Method)
90
[Height=240, IsInitialized=false, Width=320
]
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
What version of Android are you using? This is only available from 4.2 (API level 17) see the documentation here.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Your code is correct. I'm not sure why there isn't a shutter sound.
I know this is an old thread, however I have the same problem on both my Nexus 7 & Galaxy S3. Even though the shutter sound should be enabled by default, I have also tried calling EnableShutterSound(True) in my code & I still can't get it to work. I don't think it's an issue with the devices, because I put:

B4X:
Private Sub Play_Click_Sound
    Dim mp As MediaPlayer
   
    mp.Initialize
    mp.Load("/", "system/media/audio/ui/camera_click.ogg")
    mp.Play
End Sub

into the CameraExClass & call it from TakePicture:

B4X:
Public Sub TakePicture
    Play_Click_Sound
    cam.TakePicture
End Sub

& I get the sound. Any clues as to why there is no sound via the Camera library / CameraExClass?

Thanks - Colin.
 
Upvote 0

aeropic

Active Member
Licensed User
Longtime User
I have also tried calling EnableShutterSound(True) in my code & I still can't get it to work.


Hi Colin,
I get the same problem with my galaxy S3: no sound with cameraEx.
Moreover when trying this code: (uncommented "if .. then")
B4X:
If api >= 17 Then
                'If camEx.canDisableShutterSound Then
                    camEx.enableShutterSound(True)
                    ToastMessageShow("ok",False)
                'End If
           End If

with the following declaration in camEx :
B4X:
Public Sub EnableShutterSound(Enabled As Boolean) As Boolean
r.target = nativeCam
Return r.RunMethod2("enableShutterSound", Enabled, "java.lang.boolean")
End Sub

Public Sub canDisableShutterSound As Boolean
r.target = parameters
    Return r.RunMethod("canDisableShutterSound")
End Sub

I get a JAVA exception canDisableShutterSound unknown method...
My S3 runs jellybean 4.3 with API >= 17... It should work ?
 
Upvote 0

aeropic

Active Member
Licensed User
Longtime User
me again ...

I've just tried the "Play_Click_Sound" routine...
It works not too bad with the standard "camera_Click.ogg" sound but fails with others:
B4X:
Private Sub Play_Click_Sound
    Dim mp As MediaPlayer
  
    mp.Initialize
   ' mp.Load("/", "system/media/audio/ui/camera_click.ogg")
    ' mp.Load("/", "system/media/audio/ui/camera_Stop.ogg")
      mp.Load("/", "system/media/audio/ui/call_Connect.ogg")
    mp.Play

In fact any other sound fails... with this Java IOException. In addition the camera_Click is not systematically well played. Sometimes it does not play at all, sometimes it just plays 50% ...

Any Idea ?

java.io.IOException: Prepare failed.: status=0x1
at android.media.MediaPlayer.prepare(Native Method)
at anywheresoftware.b4a.objects.MediaPlayerWrapper.loadAfterReset(MediaPlayerWrapper.java:97)
at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:62)
at com.aeropic.CameraUnlockFree.cameraexclass._play_click_sound(cameraexclass.java:1279)
at com.aeropic.CameraUnlockFree.cameraexclass._takepicture(cameraexclass.java:2042)
at com.aeropic.CameraUnlockFree.cameraexclass._camera_focusdone(cameraexclass.java:83)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.objects.CameraW$3.onAutoFocus(CameraW.java:195)
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:886)
at android.os.Handler.dispatchMessage(Handler.java:99)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:200)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:168)
at anywheresoftware.b4a.keywords.Common.DoEvents(Common.java:380)
at com.aeropic.CameraUnlockFree.a01._btnfocus_click(a01.java:841)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
at android.view.View.performClick(View.java:4475)
at android.view.View$PerformClick.run(View.java:18786)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
java.io.IOException: Prepare failed.: status=0x1
 
Upvote 0

aeropic

Active Member
Licensed User
Longtime User
thanks Erel. Indeed with this code
B4X:
 mp.Initialize
    'mp.Load("/", "system/media/audio/ui/camera_click.ogg")
     mp.Load("/", "system/media/audio/ui/camera_Stop.ogg")
    '  mp.Load("/", "system/media/audio/ui/call_Connect.ogg")
placed in initialize routine of CamEx I get it working fine with "camera_click.ogg" sound.
But it does not work with other sounds and generates the exception

java.io.IOException: Prepare failed.: status=0x1
at android.media.MediaPlayer.prepare(Native Method)
at anywheresoftware.b4a.objects.MediaPlayerWrapper.loadAfterReset(MediaPlayerWrapper.java:97)
at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:62)
at com.aeropic.CameraUnlockFree.cameraexclass._initialize(cameraexclass.java:1218)
at com.aeropic.CameraUnlockFree.a01._initializecamera(a01.java:1748)
at com.aeropic.CameraUnlockFree.a01._camera1_ready(a01.java:1292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:853)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:810)
at com.aeropic.CameraUnlockFree.cameraexclass._camera_ready(cameraexclass.java:186)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.objects.CameraW$2$1.run(CameraW.java:139)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:200)
at anywheresoftware.b4a.Msgbox.debugWait(Msgbox.java:158)
at anywheresoftware.b4a.debug.Debug.wait(Debug.java:213)
at anywheresoftware.b4a.debug.Debug.reachBP(Debug.java:260)
at anywheresoftware.b4a.debug.Debug.ErrorCaught(Debug.java:145)
at com.aeropic.CameraUnlockFree.cameraexclass._initialize(cameraexclass.java:1224)
at com.aeropic.CameraUnlockFree.a01._initializecamera(a01.java:1748)
at com.aeropic.CameraUnlockFree.a01._timer1_tick(a01.java:2124)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0
Top