[SOLVED] Capturing Android events

edited November 2011 in Help request
Another day, another Android question.

Is there functionality in place (or easily implemented) to listen for Android events? I know the Android "Back" button is bound to the Orx KEY_ESCAPE input (well, "know"...I mean I've tried it and it works); are there any others, for instance the Menu button or volume rocker/buttons?

More generally, I was going to look through the Orx SVN code myself, and see if I could find where the "Back"->KEY_ESCAPE mapping took place, and extrapolate from there; but I realised I had no idea where in the SVN folders that might be. trunk/code/include and trunk/code/src are for the vanilla Orx library; where are the Android-specific implementations?

Thanks for any clarification!



  • edited November 2011
    Oh, hang on. Could these files be in code/plugins/Keyboard/android/orxKeyboard.cpp? I can see NV_KEYCODE_MENU getting mapped to orxKEYBOARD_KEY_MENU there, for instance. Nothing for the volume buttons necessarily, but it's a start.
  • edited November 2011

    You're completly right. Orx manage his different plateform using plugins, so you can find all of them under code/plugins/. And you give us the good path for the android keyboard.

    Now, as I said, the android port used an external library, made by NVidia. This external library is in externNvEvent.

    I just search NV_KEYCODE_MENU in this folder, and I found the place where this is used, and as I can see, the volume isn't managed actually by the NVEvent part. I found on the android developper website that sound event can be managed by KEYCODE_VOLUME_DOWN/UP.

    But, you can add this to nvevent/orx, exactly like other event. It's something like doing some copy/replace/paste.

    The actual version of the NVEvent isn't the orginal. I made some change inside for multitouch purpose, and lydesik too I think.

    If you want to add some support for this event, I suggest you to modify the nvevent framework, modify the android part under code/plugins/, compile the nvevent library (I think you have to do a "make" in the extern/nvevent/build/ folder), compile orx (run make in the code/build/android folder or something like that) and commit your change when it's working.

    If you aren't be able to do that, maybe Iarwain can give you access on the svn ? And if you don't know what I said, I can do that for you, but you will have to wait, I don't really have the time actually ... Maybe next week, don't know.

    It's ok ?
  • edited November 2011
    Wow, that did it! Fairly straightforward too, just had to make sure I knew which files to edit, and where.

    Only issues now:
    - Since Orx doesn't have explicit "Volume Up/Down" keyboard inputs of its own, I've mapped them to Page Up/Down for the time being. Strikes me as a bit of a hack though, so I don't want to commit the change before discussing with you folks.
    - With those keybindings, I can receive volume up/down events just fine. When I get volume up, for instance, I just call orxSoundSystem_SetGlobalVolume() to increment the volume, and vice versa. Only thing is, I'm not sure what values to use: is 0.0f mute and 1.0f full volume, for instance? Or is the range something other than that?

    Thanks for the help!
  • edited November 2011
    I should probably add key IDs for volume up/down. I'll try to do it tonight.

    And yes, 0.0 is mute, 1.0 is the actual volume of the sample/stream, and anything above will be louder but is also more likely to produce saturated results.
  • edited November 2011
    Hi newton64...

    in general on Android, it's a bad idea to trap volume up/down event...
    you should let android handle it by itself.

    So the question is why are you doing that, or why do you need to call orxSoundSystem_SetGlobalVolume()?

    In my game, i'm not binding vol+/vol- in orx, still using thoses key while the game is running change the volume of the music and the SFX...
  • edited November 2011
    Oh btw, I'm not sure if I'll add these key IDs in the end as there's no standardization on computers and Apple completely forbid to listen for these key events if you want to publish on the AppStore (actually the only way to know what's going on with them is to use a private hidden API and that's the part which is forbidden).
  • edited November 2011
    Hmm...yeah, that makes sense.

    I'm about to put my game on the Android Market, so I'd sent copies out to a few of my friends with Android devices. All of them seem to have it running okay, except one guy. He has a few recurring and bizarre bugs that keep cropping up, and I have no idea why. Like, they fall into the realm of "this is technically impossible, but it's happening anyway": game states transitioning when there is literally no actual call to do so, and so on. Weird stuff.

    Anyway, he was also asking why my game is so loud, and actually playing it on his phone, I can see he's right...it's intense! And his volume rocker doesn't seem to work while he's playing the game.

    He does have a jailbroken phone with a few other mods installed besides. I'm sort of hoping that's the issue. In any case, don't worry about the volume controls; I'll leave things as-is and let the device do the modifications.
  • edited November 2011
    Oddly enough, when I play Gravity, I can hit the volume rocker, and I see the Android volume pop-up working, and the volume actually changes. When I hit the same buttons while playing my game, the pop-up doesn't appear, and the volume stays constant. Is there perhaps a permission I'm forgetting?
  • edited November 2011
    Okay, fixed this one too. The problem is that the volume rocker (by default) only affects the volume of whatever's playing---if an app is playing sound, the Media Volume gets changed; but if there's nothing else playing, the ringer's volume is changed. My game has a lot of "dead air," so the volume rocker was changing arbitrary volumes.

    I found this site, where a solution is offered. In the game's Java Activity, import the Android audio manager:
    import android.media.AudioManager;

    ...and then call the following in your overridden onCreate() function:

    This will ensure that using the volume rocker will apply to Media Volume (which includes all audio coming from your game. You can also call the following in onDestroy() to return to the default audio setting:
  • edited November 2011
    Good to know!

    Should this be called by default in orx's java activity then?
  • edited November 2011
    Well, that's up to you for the most part, I wouldn't presume to tell you what to do with your library ;)

    But I imagine it may clear up some problems for other coders in the future.
  • edited November 2011
    Ahah, well, I guess my question was aimed at Lydesik who's the mastermind behind the Android version (assisted by Faistoiplaisir, of course).
    Shamefully I have yet to try the Android version myself. :)
  • edited December 2011
    yup I should call thid in Sound::Init() plugin

    will look at this when i can find some free time
  • edited January 2012

    Until now, orxSoundSystem_SetGlobalVolume() (and Get) for android was not implemented.

    It's done now in the actual svn version.

    This global volume is apply on the sound at the last time, when the volume is passed to the Java part.

    This function doesn't set the phone's volume, it's apply to the orxSOUND object. So when orxSoundSystem_SetGlobalVolume is set to 1.0, sounds are played at the phone's volume.

    I use this function to create a "mute" button.

    Since few day, there's 2 new types of fx : volume and pitch. So you can easily create some fade in / fade out effect for example.

    Hope this can help !
  • edited January 2012
    That sounds great! Thanks for sharing :)
  • edited January 2012
    Thanks a lot for the 2 new FX types, faistoiplasir! =)

    A small question though, just to be sure the Android plugin is behaving like all others: when you set a global volume, does it override the local sound volume or is it used as a multiplier?

    The way it's supposed to work is that global volume is actually a multiplier, hence if SoundA.Volume = 0.5 and SoundB.Volume = 1.0, when having a GlobalVolume of 0.5, it's equivalent of having SoundA.Volume = 0.25 and SoundB.Volume = 0.5.
    If it already behaves that way it's great, otherwise do you think you could change it for consistency sake?

    Thanks again! =)
  • edited January 2012
    Hey Iarwain !

    For the 2 fx types, you're welcome ^^ It was not really hard to do, just a bunch of copy/paste tricks ;)

    For the global volume, actually behaviour is exactly whats you said in your example, so it's perfect :)

    Cheers !
  • edited January 2012
    faistoiplaisir wrote:
    For the global volume, actually behaviour is exactly whats you said in your example, so it's perfect :)

    Excellent, thanks! :)
Sign In or Register to comment.