Change volume

WAZUMBi

Well-Known Member
Licensed User
Longtime User
OK so I've tried:

B4X:
   If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then
      If phoneData.GetVolume(phoneData.VOLUME_MUSIC) > 0 Then
         phoneData.SetVolume(phoneData.VOLUME_MUSIC, phoneData.GetVolume(phoneData.VOLUME_MUSIC) - 1, True)
      End If   
   End If
   
   If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
      If phoneData.GetVolume(phoneData.VOLUME_MUSIC) < phoneData.GetMaxVolume(phoneData.VOLUME_MUSIC) Then
         phoneData.SetVolume(phoneData.VOLUME_MUSIC, phoneData.GetVolume(phoneData.VOLUME_MUSIC) + 1, True)
      End If   
   End If

And my program just crashes and i get an Andoid system error message

So then I tried to break it down with:

B4X:
dim temp as int

   If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then      
      temp = phoneData.GetVolume(phoneData.VOLUME_MUSIC)
      If temp > 0 Then
         temp = temp - 1
         phoneData.SetVolume(phoneData.VOLUME_MUSIC, temp, True)
      End If      
   End If

   If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then      
      temp = phoneData.GetVolume(phoneData.VOLUME_MUSIC)
      If temp < phoneData.GetMaxVolume(phoneData.VOLUME_MUSIC) Then
         temp = temp + 1
         phoneData.SetVolume(phoneData.VOLUME_MUSIC, temp, True)
      End If      
   End If

This does change the volume AND then crashes with the same Android system error message.

Any ideas what I'm doing wrong here?
 

WAZUMBi

Well-Known Member
Licensed User
Longtime User
pretty generic:

"Sorry! The application interblock(process interblock.Interblock) has stopped unexpectedly. Please try again."

Still trying to figure out how to use logcat
 
Upvote 0

WAZUMBi

Well-Known Member
Licensed User
Longtime User
Log(KeyCode)
Log(phoneData.GetVolume(phoneData.VOLUME_MUSIC))
Log(phoneData.GetMaxVolume(phoneData.VOLUME_MUSIC))

When I press volume down the log shows
25
3
15

volume up shows
24
4
15

no errors show up in the log
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Still trying to figure out how to use logcat

Just go to the Logs tab:
SS-2012-02-05_12.35.14.png
 
Upvote 0

WAZUMBi

Well-Known Member
Licensed User
Longtime User
Alright figured that out.


sendVolumeUpdate VOLUME_CHANGED_ACTION streamType = 3
Received intent Intent { act=android.media.VOLUME_CHANGED_ACTION (has extras) }
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
removeCallbacks-mVolumekeysInCallLongPress
Input event
Dsptch to Window{4bb1c1b0 interblock.Interblock/interblock.Interblock.main paused=false}
virtual android::status_t android::AudioHardwareALSA::setFmRadioVolume(float) : Volume = [0.089125]
Received intent Intent { act=android.media.VOLUME_CHANGED_ACTION (has extras) }
mReceiver: VOLUME_CHANGED_ACTION
stream: 3
volume: 8
FATAL EXCEPTION: main
java.lang.ClassCastException: java.lang.String
at interblock.Interblock.main.onKeyDown(main.java:131)
at android.view.KeyEvent.dispatch(KeyEvent.java:1043)
at android.app.Activity.dispatchKeyEvent(Activity.java:2068)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1705)
at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2496)
at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2466)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1760)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Dumpstate > /data/log/dumpstate_app_error
Force finishing activity interblock.Interblock/.main
GC_FOR_MALLOC freed 11695 objects / 567968 bytes in 113ms
begin
Timer 0x7->0x3|0x3
Ulight 7->3|0
system <- value=8 name=volume_music
property: sys.settings_system_version=909
setScreenOffTimeouts mKeylightDelay=3000 mDimDelay=110000 mScreenOffDelay=7000 mDimScreen=true
setScreenOffTimeouts mKeylightDelay=3000 mDimDelay=110000 mScreenOffDelay=7000 mDimScreen=true
notifying: content://settings/system/volume_music
system <- value=8 name=volume_music_last_audible
property: sys.settings_system_version=910
setScreenOffTimeouts mKeylightDelay=3000 mDimDelay=110000 mScreenOffDelay=7000 mDimScreen=true
notifying: content://settings/system/volume_music_last_audible
asec list
 
Upvote 0

WAZUMBi

Well-Known Member
Licensed User
Longtime User
Thank you. That worked like a charm.

Now the ringer and media volume changes though. I was assuming
VOLUME_MUSIC set the media volume on my device.
 
Upvote 0

WAZUMBi

Well-Known Member
Licensed User
Longtime User
I figured out if i return true it appears to work fine now however the logs show:

BAT. status:4 health:2
ACTION_BATTERY_CHANGED pluggedType: 0
Input event
Ulight 3->7|0
Dsptch to Window{4bd43058 interblock.Interblock/interblock.Interblock.main paused=false}
24
sendVolumeUpdate VOLUME_CHANGED_ACTION streamType = 3
Received intent Intent { act=android.media.VOLUME_CHANGED_ACTION (has extras) }
virtual android::status_t android::AudioHardwareALSA::setFmRadioVolume(float) : Volume = [0.251189]
Received intent Intent { act=android.media.VOLUME_CHANGED_ACTION (has extras) }
mReceiver: VOLUME_CHANGED_ACTION
stream: 3
volume: 11
Input event
removeCallbacks-mVolumekeysInCallLongPress
Dsptch to Window{4bd43058 interblock.Interblock/interblock.Interblock.main paused=false}
sendVolumeUpdate VOLUME_CHANGED_ACTION streamType = 2
Received intent Intent { act=android.media.VOLUME_CHANGED_ACTION (has extras) }
Received intent Intent { act=android.media.VOLUME_CHANGED_ACTION (has extras) }
mReceiver: VOLUME_CHANGED_ACTION
stream: 2
volume: 4
getAudioMode[0]
ALSA OPEN mode 0,device 2
Try to open ALSA PLAYBACK device AndroidPlayback_Speaker_normal
Initialized ALSA PLAYBACK device AndroidPlayback_Speaker_normal
Set PLAYBACK PCM format to S16_LE (Signed 16 bit Little Endian)
Using 2 channels for PLAYBACK.
Set PLAYBACK sample rate to 44100 HZ
Buffer size: 2048
Latency: 46439
system <- value=11 name=volume_music
property: sys.settings_system_version=1062
setScreenOffTimeouts mKeylightDelay=3000 mDimDelay=110000 mScreenOffDelay=7000 mDimScreen=true
notifying: content://settings/system/volume_music
system <- value=11 name=volume_music_last_audible
property: sys.settings_system_version=1063
setScreenOffTimeouts mKeylightDelay=3000 mDimDelay=110000 mScreenOffDelay=7000 mDimScreen=true


The system is doing 2 calls - one to channel 3 and then to channel 2. Only the music volume is changed though.

I ran a different app from the market and when I press the volume buttons it also makes two calls but both are to channel 3.

So while my code works, it appears to be doing it incorrectly.
 
Upvote 0
Top