B4A Class Audio Visualizer

Discussion in 'Additional libraries, classes and official updates' started by stevel05, Jun 9, 2014.

  1. stevel05

    stevel05 Expert Licensed User

    What device are you running it on? It needs Android 2.3+
     
  2. stevel05

    stevel05 Expert Licensed User

    @fanfalveto Sorry I missed your post, did you get it sorted?
     
  3. Agnetha

    Agnetha Member Licensed User

    It's a Tablet "Endeavour 1000HD" with Android 4.1.1.
    I've updatet to API-Level 21 - without success.
     
  4. stevel05

    stevel05 Expert Licensed User

    Sorry just checked again, the Visualizer.MeasurementPeakRms class is only available from 4.4 (KitKat) if you can get the upgrade to work, it should be OK.
     
  5. Agnetha

    Agnetha Member Licensed User

    Thank you!
     
  6. jeng

    jeng Member Licensed User

    Hello,

    I get a strange error, IndexOutOfBoundsException: index 7 if i try to playback my recording.
    Can some one help me out with this? or push me to the right direction ;-)
    Code:
    at java.util.concurrent.atomic.AtomicIntegerArray.checkedByteOffset(AtomicIntegerArray.java:35)
        at java.util.concurrent.atomic.AtomicIntegerArray.get(AtomicIntegerArray.java:
    82)
        at anywheresoftware.b4a.debug.Debug.ShouldStop(Debug.java:
    230)
        at VrM.Jeng.main._mp_complete(main.java:
    1278)
        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.MediaPlayerWrapper$
    1.onCompletion(MediaPlayerWrapper.java:52)
        at android.media.MediaPlayer$EventHandler.handleMessage(
    MediaPlayer.java:2437)
        at android.os.Handler.dispatchMessage(Handler.java:
    99)
        at anywheresoftware.b4a.Msgbox.waitForMessage(
    Msgbox.java:198)
        at anywheresoftware.b4a.Msgbox.debugWait(
    Msgbox.java:157)
        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 VrM.Jeng.main._button_click(main.java:
    569)
        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:77)
        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:
    176)
        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:
    1046)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    862)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:
    132)
        at dalvik.system.NativeStart.main(Native Method)
    java.lang.IndexOutOfBoundsException: index 
    7
    Here my test project:
     

    Attached Files:

    • VrM.zip
      File size:
      20.1 KB
      Views:
      34
  7. Pavka

    Pavka Member Licensed User

    Hi, is it possible to use visualizer module in live wallpapers? When I tried I had en error.
     
  8. Zerberus

    Zerberus Member Licensed User

    Hello stevel05,

    I want to use your Audio Visualizer to build a little lighting console for my little mp3-player-app.

    My question: How can i log the peak with the getMeasurementPeakRms-method? I try "log(Viz.getMeasurementPeakRms.mPeak)" after "MP.Play", but i get error "MeasurementPeakRms cannot be cast to java.lang.Object[]". Also when i try
    Code:
    Dim test As Int
    test=(Viz.getMeasurementPeakRms.mPeak)
    What is my mistake?

    Greetings

    Zerberus
     
  9. stevel05

    stevel05 Expert Licensed User

    Hi Zerberus,

    You've found a Bug, Change Line 73 in the Vizualizer class to:

    Code:
    Viz.RunMethod("getMeasurementPeakRms",Array(PRMS))
    or

    Code:
    Viz.RunMethod("getMeasurementPeakRms",Array As Object(PRMS))
    If you are using an older version of B4a.
     
    lemonisdead and Zerberus like this.
  10. Zerberus

    Zerberus Member Licensed User

    Thanks,

    I will try it.

    EDIT: Hmmm...
    I wrote
    Code:
    Dim Timer As Timer
    ...
    Timer.Initialize("Timer"100)
    Timer.Enabled=True
    ...
    Sub Timer_Tick
    Log(Viz.getMeasurementPeakRms.mPeak)
    End Sub
    but the Log shows always "0". I want to use the peak-level of the played song to recognize the "beat" (for some visual effects).
     
    Last edited: Jan 19, 2016
  11. stevel05

    stevel05 Expert Licensed User

    Zerberus likes this.
  12. Zerberus

    Zerberus Member Licensed User

    Thanks,

    now I receive results!

    Greetings

    Zerberus
     
  13. Zerberus

    Zerberus Member Licensed User

    Now I have a little "peakmeter" (in attachment).

    Is it possible to receive a range of frequencies (like "bass", "middle", "high") and combine this with the actual peak (the bass-drum hits the beat...)?

    Greetings

    Zerberus
     

    Attached Files:

  14. stevel05

    stevel05 Expert Licensed User

    I think for that you would need to analyse the FFT data, I'm afraid I don't have a working knowledge of doing this.
     
    Zerberus likes this.
  15. Zerberus

    Zerberus Member Licensed User

    Hmmm...

    It seems the peak-level is dependent on the VOLUME_MUSIC. Can i get an undependent peak-level?
     
  16. moster67

    moster67 Expert Licensed User

    Nice class/project @stevel05. Thank you!

    I had a play with it and it worked nicely on all my devices I tried it with.

    Decided to try it with some of the other mediaplayers available and see if I could get it working with audio-sources not supported by the standard MediaPlayer. With Vitamio5 and FFmpeg_b4a it works fine although not on all devices (there is apparently a workaround for that so I am going to check it out). Unfortunately it won't work at all with vlcb4a.

    Using the demo-project provided by @stevel05, the important thing is to set the AudioSession to 0 (zero) and of course use your mediaplayer as an instance instead of the standard MediaPlayer. Some other minor changes are also needed such as method names to start playing, stopping etc but they are rather obvious.
     
    Last edited: May 6, 2017
    stevel05 likes this.
  17. Douglas Farias

    Douglas Farias Expert Licensed User

    Hi @stevel05 .
    i m tryed to use your example class, and i got this error.

    Code:
    ** Activity (main) Create, isFirst = true **
    AS 12313
    Error occurred on line: 
    12 (Vizualizer)
    java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:
    343)
        at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(
    JavaObject.java:90)
        at exemplo.batida.vizualizer._initialize(vizualizer.java:
    63)
        at exemplo.batida.main._activity_create(main.java:
    407)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:732)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:348)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:255)
        at java.lang.reflect.Method.invoke(Native Method)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    144)
        at exemplo.batida.main.afterFirstLayout(main.java:
    104)
        at exemplo.batida.main.access$
    000(main.java:17)
        at exemplo.batida.main$WaitForLayout.run(main.java:
    82)
        at android.os.Handler.handleCallback(Handler.java:
    873)
        at android.os.Handler.dispatchMessage(Handler.java:
    99)
        at android.os.Looper.loop(Looper.java:
    201)
        at android.app.ActivityThread.main(ActivityThread.java:
    6810)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:
    547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    873)
    Caused by: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -
    3
        at android.media.audiofx.Visualizer.<init>(Visualizer.java:
    218)
        ... 
    21 more
    ** 
    Activity (main) Resume **
    its your example, without changes.

    B4A 9.30 (XIAOMI with Android 9), java 11 (compiled with sdk 26)
    I have the same error in debug AND release.

    what can cause this? and its possible fix?

    thank you.
     
    Last edited: Sep 8, 2019
  18. stevel05

    stevel05 Expert Licensed User

    Hi Douglas, sorry I won't be able to look at it for a couple of days, maybe someone already knows the answer, if not I'll take a look when I can.
     
    Douglas Farias likes this.
  19. Douglas Farias

    Douglas Farias Expert Licensed User

    i found this, only use runtime permissions and it is fixed. thank you for the lib.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice