Android Music Visualizer w/ Particle System - Black Cauldron

edited December 2017 in Share Your Work

It's been my great pleasure over the last 6 weeks or so to develop and release the Black Cauldron Music Visualizer: https://play.google.com/store/apps/details?id=com.wordpress.deivescollins.blackcauldronfree. (For those without Android devices, the promotional video: https://www.youtube.com/watch?v=hnKDLob5d2M.) Yes, this would have been possible to do in another toolset, but Processing proved to be the best for my workflow and developing this type of application in general, especially with the Android support. I had never designed for Android before, and I don't think I particularly want to without Processing (or Unity maybe, for a different project).

The link above is to the free version. If you really enjoy it and get annoyed with the ads, check out the $1 version--or, if you really don't want to pay for it, message me and we can probably work something out.

I'm not releasing the source code for this, but I am happy to answer questions about how it was done generally.

Comments

  • edited December 2017

    @Rammschnev -- congratulations on releasing your project!

  • Congratulations on releasing the music visualizer. I'm also a budding coder and have completed an audio app for android. Cld you pl let me know how do you code the record audio permission, that is, just a requestPermission() in setup or a whole lot of other codes too? My simple requestPermission with two arguments managed to turn the mic for the app on in my phone but then crashed. I don't know if it is not linked properly to the main code or something like that. Completed the app but stuck at this last thing. Can you pl help?

  • edited December 2017

    (Edit: I'm going to leave out the @ before 'Override' because it's confusing the forum)

    @sonia It was a major sticking point for me as well. Thing is Android changed the way permissions work in 6.0, which I didn't realize before releasing my app and had to haul ass to figure out what was wrong. My implementation might not be the most sophisticated (I'm kind of a sloppy coder in some respects; I just like a simple app structure), but it does work 100% of the time for me. I'll try to reduce my code down to an example that makes sense.

    First of all, if it isn't already, this needs to be in your main activity (copied and pasted from one of the processing.org tutorials):

    Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        if (sketch != null) { // Assuming your PApplet is named 'sketch'
            sketch.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
    

    Next, I basically have my setup() method delay from executing until the permission is granted (because in my case, the app simply won't function at all without the permission; in general, the most professional thing to do is to try to offer all the functionality possible without the permission until it's granted). I keep track of whether the setup function has executed successfully with a simple static (<- important) boolean initialized in the sketch class (extending PApplet). So, in other words:

    public class Sketch extends PApplet {
        public static boolean initialized = false;
        // ...
        Override
        public void setup() {
            // This must go first
            if (!hasPermission("android.permission.RECORD_AUDIO")) {
                requestPermission("android.permission.RECORD_AUDIO");
                return; // Notice we exit from the method here
            } 
    /* You don't need to do this ^ with all permissions, just permissions that Android
        considers 'dangerous' */
    
            // Setup stuff
            // ...
            initialized = true;
        }
    }
    

    My draw() then looks like this:

    Override
    public void draw () {
        if (hasPermission("android.permission.RECORD_AUDIO")) {
            if (initialized) {
                // My actual draw commands
            }
            else {
                setup();
            }
        }
    }
    

    The variable initialized was actually originally brought in for another reason. It helps in dealing with the fact that setup() is called every time the screen resizes, so you can make sure your whole app doesn't reset that way as well, if you haven't already worked something like that out.

    I think this is all you need to know. Hope it helps. I was exactly where you are (or maybe have gotten past by now), and it's maddening. Let me know if you have any follow-up questions. Best of luck

  • Thanks a lot ! It works, works perfectly. Didn't know I needed to turn my sketch into a class and extend PApplet. I tried all kinds of things for a few days and none of it worked. Btw, I am not using Android Studio, so there is no main activity file. But, the other code by itself works. So, that's great. I do have follow-up questions, of course. But, that will be in the course of time, like, say if I needed to use buttons or a welcome page, etc., (as of now, its a raw app in terms of 'packaging'), I might have to figure out where to fit it all in the structure, and so on. Thanks again. A big worry off my mind...

Sign In or Register to comment.