Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use extended TextureView #6

Open
TorstenH82 opened this issue Oct 14, 2024 · 1 comment
Open

Use extended TextureView #6

TorstenH82 opened this issue Oct 14, 2024 · 1 comment

Comments

@TorstenH82
Copy link

I don't know if this project is still alive...

Based on the sample code I extended a TextureView I can directly add to the layout file.
I feed the method onWaveFormDataCapture with PCM audio data but the animation does not start. I additionally call the method onSurfaceTextureAvailable not this does not fix the issue.

Would be great to get some support here...

package com.thf.dabplayer.activity;

import android.content.Context;
import android.util.AttributeSet;
import android.view.TextureView;
import android.view.View;
import com.nekocode.musicviz.FFTFrame;
import com.nekocode.musicviz.WaveFormFrame;
import com.nekocode.musicviz.render.GLScene;
import com.nekocode.musicviz.render.SceneController;
import com.nekocode.musicviz.render.VisualizerRenderer;
import com.nekocode.musicviz.scene.BasicSpectrumScene;

public class TextureViewVis extends TextureView {
    private Context context;
    private static VisualizerRenderer mRender;
    private SceneController mSceneController;
    private int captureSize = 512;

    public TextureViewVis(final Context context) {
        super(context);
        this.context = context;
        initView(context);
        // setVideoLayout(mVideoLayout);
    }

    public TextureViewVis(final Context context, final AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        initView(context);
    }

    public TextureViewVis(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
        initView(context);
    }

    private void initView(Context context) {
        this.setSurfaceTextureListener(mRender = new VisualizerRenderer(context, captureSize / 2));
        this.addOnLayoutChangeListener(
                new View.OnLayoutChangeListener() {
                    @Override
                    public void onLayoutChange(
                            View v,
                            int left,
                            int top,
                            int right,
                            int bottom,
                            int oldLeft,
                            int oldTop,
                            int oldRight,
                            int oldBottom) {

                        mRender.onSurfaceTextureSizeChanged(null, v.getWidth(), v.getHeight());
                    }
                });

        this.requestLayout();

        mRender.setSceneController(
                mSceneController =
                        new SceneController() {
                            @Override
                            public void onSetup(
                                    Context context, int audioTextureId, int textureWidth) {
                                // mSceneList = new ArrayList<>();
                                GLScene defaultScene =
                                        new BasicSpectrumScene(
                                                context, audioTextureId, textureWidth);
                                /*
                                                mSceneList.add(Pair.create("Basic Spectrum", defaultScene));
                                                mSceneList.add(Pair.create("Circle Spectrum", new CircSpectrumScene(context, audioTextureId, textureWidth)));
                                                mSceneList.add(Pair.create("Enhanced Spectrum", new EnhancedSpectrumScene(context, audioTextureId, textureWidth)));
                                                mSceneList.add(Pair.create("Input Sound", new InputSoundScene(context, audioTextureId, textureWidth)));
                                                mSceneList.add(Pair.create("Sa2Wave", new Sa2WaveScene(context, audioTextureId, textureWidth)));
                                                mSceneList.add(Pair.create("Waves Remix", new WavesRemixScene(context, audioTextureId, textureWidth)));
                                                mSceneList.add(Pair.create("Rainbow Spectrum", new RainbowSpectrumScene(context, audioTextureId, textureWidth)));
                                                mSceneList.add(Pair.create("Chlast", new ChlastScene(context, audioTextureId, textureWidth)));
                                                mSceneList.add(Pair.create("Origin Texture", new OriginScene(context, audioTextureId, textureWidth)));
                                */
                                changeScene(defaultScene);

                                // invalidateOptionsMenu();
                            }
                        });
        
        this.setOpaque(false);
    }

    public static void onFftDataCapture(byte[] fft) {
        mRender.updateFFTFrame(new FFTFrame(fft, 0, fft.length / 2));
    }

    private boolean isAvailable = false;

    public void onWaveFormDataCapture(byte[] waveform, int len) {

        if (this.isAvailable()) {
            if (!this.isAvailable) {
                mRender.onSurfaceTextureAvailable(
                        this.getSurfaceTexture(), this.getWidth(), this.getHeight());
                this.isAvailable = true;
            }
        } else {
            this.isAvailable = false;
        }

        mRender.updateWaveFormFrame(new WaveFormFrame(waveform, 0, len));
    }
}
@TorstenH82
Copy link
Author

Let me add that I can't use the Visualizer because the RECORD_AUDIO permission is a no-go and the audio data is already available as PCM byte array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant