Quick Links: Download Gideros Studio | Gideros Documentation | Ultimate Guide | Gideros Development Center
Microphone Plugin on Android - zero length sound file - Gideros Forum

Microphone Plugin on Android - zero length sound file

saeyssaeys Member
edited March 28 in Plugins
Hey there, earlier on I've had my troubles with the microphone plugin on Android, but eventually I got it in a stable working order (without me really knowing what was wrong before). Now, when it's time for an update the microphone part in my project appears non-functional again.

I've "rolled back" to the Microphone plugin example project, and it behaves the same.
I can press Record, press Record Stop, but when I press Play it's playing back a zero seconds long sound file, since the button immediately returns to an 'up' state. Obviously the app creates a sound file, because initially Play button is disabled, but once something is "recorded" the Play button is enabled. Also, getLength() on sound returns 0 (zero).

I get no errors, no crashes. I have no idea how to debug this further.
This applies only on Android devices. On PC (Gideros player) and iOS it works like as expected.
Tried direct apk export (from 2017.3.1) as well as export via Android Studio, same behavior.
Exporting using Android SDK Version 25 and Tools 25.0.1, Java JDK 1.8.0_121.

Clues, anyone?


  • hgy29hgy29 Maintainer
    Which android version are you targeting? There is a serious chance that android 21+ permission system broke microphone
  • saeyssaeys Member
    edited March 28
    In build.gradle:
    minSdkVersion 9
    targetSdkVersion 19

    The devices I'm testing on is API 22 and 25. The mic in an old version of the app is working fine on the 22, I just don't dare to update it...

    Edit: Oh, I *have* updated it, but only from Android Studio (new icon), from where it works, not from a new Gideros Studio export.
  • saeyssaeys Member
    edited March 29
    Hey @hgy29 I admit I didn't get your question at first, sorry. :|

    If you mean which compiling API level it's 25 with tools 25.0.1, Android Studio won't settle with lower tools version than 25.0.0. I am pretty sure the microphone previously has been in working order under at least API 22.

    But even if it is an issue with permissions (or anything else), is there a competent angel out there that is able to fix what has become broken? :o3
  • hgy29hgy29 Maintainer
    The important version here is targetSdk, if it is 19 as you said then it should work as it used to. To explain better: android has changed the way permissions are granted in SDK 23 (sorry, it wasn't 21): if you target SDK 23 dangerous permissions must be requested by the app code instead of just being declared in the manifest, and I am pretty sure gideros mic plugin doesn't do that.

    So if you target SDK23, record_audio permission won't be granted to the plugin since it doesn't explictly request it. If you continue to target a lower version, then old permission checking is applied and it should work as before.

    Aye: saeys

    +1 -1 (+1 / -0 ) Share on Facebook
  • saeyssaeys Member
    Well then it must be something else than only a permissions issue since I'm on targetSdk 19, at least if it is targetSdk that matters in this case (and not compileSdkVersion etc). Tried also other levels, same results, no crashes. (If I comment out the RECORD_AUDIO permission line in the manifest the app crashes regardless of which targetSdkVersion is used, but I guess that is expected.)

    So, apart from establishing the fact that the gideros mic plugin probably isn't working when targeting newer Android versions, I'm back at square one. :-(

    More clues, anyone?
  • hgy29hgy29 Maintainer
    Maybe your logcat has some clues ? PM it to me and I'll have a look

    Aye: saeys

    +1 -1 (+1 / -0 ) Share on Facebook
  • hgy29hgy29 Maintainer
    Accepted Answer
    @saeys: I was able to reproduce the issue... and fix it!
    In your GMicrophone.java, change sActive initial value from false to true (line 13):
    private static boolean sActive = true;

    Aye: saeys

    +1 -1 (+1 / -0 ) Share on Facebook
  • saeyssaeys Member
    edited March 30
    Fantastic, thank you!! =D> Is also applicable in my own project. You made my day, really!

    I have no idea what sActive does, but I see that an old gideros export (I think 2016.8.2) with sActive = false renders a functional microphone, but the same project re-exported with 2017.3.1 does not. And the Activity.java doesn't look the same...

    Anyway I hope that setting it to true from the beginning of the class doesn't brake something else later on. X_X

    Doesn't the plugin need to be updated somewhere then (also to fit newer APIs/permissions)? I'm afraid I'm not very familiar with GitHub.
  • hgy29hgy29 Maintainer
    By the look of the code, sActive is changed to false or true when app is paused/resumed, so one could assume that when the app is launched sActive should be true by default. I tried to set it to true in onCreate(), but discovered that onCreate() is in fact never called, which is obviously a bug too.

    Aye: saeys

    +1 -1 (+1 / -0 ) Share on Facebook
Sign In or Register to comment.