Code Monkey home page Code Monkey logo

android-audio-visualizer's People

Contributors

423u5 avatar ali-heidari avatar gautamchibde avatar monkey-matt avatar rafsanjani avatar sheepyang1993 avatar shisheng-1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-audio-visualizer's Issues

Audio visualizer and services

hello, how I can create visualizer for a media player running in service,
I went to add visualizer to my main activity and get media player from service to run the visualizer
thanks

Could not find com.chibde:audiovisualizer:2.2.0.

i have used this in my build.gradle(:app) , but getting above error,pls help where i am wrong below is my build.gradle(:app) file

plugins {
id 'com.android.application'
}

android {
compileSdk 31

defaultConfig {
    applicationId "com.assistant.android.apex"
    minSdk 21
    targetSdk 31
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
    viewBinding true
}

}

dependencies {

//TODO 1 : Add Music/Audio Visualizer
implementation 'com.chibde:audiovisualizer:2.2.0'

//TODO 2a : Second library added
debugImplementation 'com.ms-square:debugoverlay:1.1.3'
releaseImplementation 'com.ms-square:debugoverlay-no-op:1.1.3'
testImplementation 'com.ms-square:debugoverlay-no-op:1.1.3'

implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

}

Error message Unable to start activity ComponentInfo{com.example.pranavapps.musicplayer/com.example.pranavapps.musicplayer.MainActivity}: android.view.InflateException: Binary XML file line #120: Binary XML file line #120: Error inflating class com.chibde.audiovisulaizer.visualizer.CircleBarVisualizer

i am creating a audio player using recycler view. Now i this app i am inserting two songs by myself
I am using circlebar visiualizer in sliding up panel.

MainActivity:-

`package com.example.pranavapps.musicplayer;

import android.annotation.SuppressLint;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import com.chibde.visualizer.CircleBarVisualizer;
import com.gauravk.audiovisualizer.visualizer.BlastVisualizer;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;

import java.io.IOException;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
Button btnPly;
Button btnPause;
Button btnNext;
Button btnPlay;
Button btnBack;
Button btnnPause;
SlidingUpPanelLayout slidingUpPanelLayout;
LinearLayout dragView;
ImageView musicImg, songImg;
TextView sngName, songName;
ArrayList arrMusic = new ArrayList<>();

RecyclerView recyclerView;
String TAG = "DemoActivity";
MediaPlayer mediaPlayer = new MediaPlayer();
Uri audioUri;

BlastVisualizer mVisualizer;
SeekBar seekBar;
byte[] art;
CircleBarVisualizer circleBarVisualizer;
LinearLayout lnrLay;

@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    musicImg = findViewById(R.id.musicImg);
    sngName = findViewById(R.id.musicName);
    btnPly = findViewById(R.id.btnPlay);
    dragView = findViewById(R.id.dragView);
    lnrLay = findViewById(R.id.lnrLay);
    btnPause = findViewById(R.id.btnPause);
    /*mVisualizer = findViewById(R.id.blast);*/
    btnnPause = findViewById(R.id.songPause);
        recyclerView = findViewById(R.id.recyclerVew);
    btnNext = findViewById(R.id.songNext);
    btnPlay = findViewById(R.id.songPLay);
    btnBack = findViewById(R.id.songBack);
    songImg = findViewById(R.id.songImg);
    songName = findViewById(R.id.songName);
    circleBarVisualizer  = findViewById(R.id.visualizer);

    //String aPath = "android.resource://" + getPackageName() + "/raw/oochi";
    //audioUri = Uri.parse(aPath);



    //songImg.setImageResource(R.drawable.ooc);
    songData("Oochi Hai Building","android.resource://"+getPackageName()+"/raw/oochi");
    songData("Sultan","android.resource://"+getPackageName()+"/raw/sultan");

    playSong();


    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

     playerAdapter playerAdapter = new playerAdapter(getApplicationContext(),arrMusic,mediaPlayer,songImg,musicImg,btnPly,btnNext,btnPlay, btnBack, btnnPause,btnPause);
    recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
    recyclerView.setAdapter(playerAdapter);

    circleBarVisualizer.setColor(ContextCompat.getColor(this, R.color.av_red));
    circleBarVisualizer.setPlayer(mediaPlayer.getAudioSessionId());
    songName.setText("o");
    //musicImg.setImageResource(R.drawable.ooc);
    sngName.setText("o");

    btnPly.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            mediaPlayer.start();
            btnPly.setVisibility(View.GONE);
            btnPause.setVisibility(View.VISIBLE);

        }
    });

   /* btnPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            mediaPlayer.pause();
            btnPause.setVisibility(View.GONE);
            btnPly.setVisibility(View.VISIBLE);

        }
    });*/

    slidingUpPanelLayout = findViewById(R.id.sliding_layout);
    slidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
        @Override
        public void onPanelSlide(View panel, float slideOffset) {
            Log.i(TAG, "onPanelSlide, offset " + slideOffset);
        }

        @SuppressLint("WrongConstant")
        @Override
        public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
            Log.i(TAG, "onPanelStateChanged " + newState);


            if (newState.equals(SlidingUpPanelLayout.PanelState.EXPANDED)) {
                lnrLay.setVisibility(View.GONE);
            } else if (newState.equals(SlidingUpPanelLayout.PanelState.COLLAPSED)) {
                lnrLay.setVisibility(View.VISIBLE);

            }
        }
    });




}

public void playSong() {


    try {
        mediaPlayer.setDataSource(MainActivity.this, audioUri);
        mediaPlayer.prepare();


    } catch (IOException e) {
        e.printStackTrace();
    }

}
public void songData(String name ,String apath){


    suitcase  suitCase = new suitcase();

    suitCase.Name = name;
    suitCase.aPath = apath;

    arrMusic.add(suitCase);

}

}`
Error :-

2019-01-16 18:33:19.946 1710-5198/system_process E/ActivityManager: applyOptionsLocked: Unknown animationType=0 2019-01-16 18:33:20.050 3319-26082/com.google.android.googlequicksearchbox:search E/ContentStoreEUAS: Failed to commit the deferred actions 2019-01-16 18:33:20.492 26556-26556/com.example.pranavapps.musicplayer E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.pranavapps.musicplayer, PID: 26556 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pranavapps.musicplayer/com.example.pranavapps.musicplayer.MainActivity}: android.view.InflateException: Binary XML file line #120: Binary XML file line #120: Error inflating class com.chibde.audiovisulaizer.visualizer.CircleBarVisualizer at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: android.view.InflateException: Binary XML file line #120: Binary XML file line #120: Error inflating class com.chibde.audiovisulaizer.visualizer.CircleBarVisualizer Caused by: android.view.InflateException: Binary XML file line #120: Error inflating class com.chibde.audiovisulaizer.visualizer.CircleBarVisualizer Caused by: java.lang.ClassNotFoundException: Didn't find class "com.chibde.audiovisulaizer.visualizer.CircleBarVisualizer" on path: DexPathList[[zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/base.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_resources_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/lib/x86, /system/lib, /vendor/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at android.view.LayoutInflater.createView(LayoutInflater.java:606) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 2019-01-16 18:33:20.497 26556-26556/com.example.pranavapps.musicplayer E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at com.example.pranavapps.musicplayer.MainActivity.onCreate(MainActivity.java:55) at android.app.Activity.performCreate(Activity.java:6975) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.pranavapps.musicplayer-iHLVF8jVG-WG4s84MaZbbg==/split_lib_resources_apk.apk at dalvik.system.DexFile.openDexFileNative(Native Method) at dalvik.system.DexFile.openDexFile(DexFile.java:353) at dalvik.system.DexFile.<init>(DexFile.java:100) at dalvik.system.DexFile.<init>(DexFile.java:74) at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374) at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337) at dalvik.system.DexPathList.<init>(DexPathList.java:157) at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65) at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64) at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43) at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69) at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:36) at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:676) at android.app.LoadedApk.getClassLoader(LoadedApk.java:709) at android.app.LoadedApk.getResources(LoadedApk.java:936) at android.app.ContextImpl.createAppContext(ContextImpl.java:2242) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5672) at android.app.ActivityThread.-wrap1(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661) ... 6 more 2019-01-16 18:33:20.638 1710-3176/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da 2019-01-16 18:33:20.639 1710-3176/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da 2019-01-16 18:33:21.229 1411-1474/? E/IPCThreadState: binder thread pool (4 threads) starved for 168 ms

Show Visualiser (com.chibde.visualizer.LineBarVisualizer) always in action even if switching activities

So i am using com.chibde.visualizer.LineBarVisualizer for some visual effect to songs playing in MediaPlayer. But the thing is when i change activity and come back to the activity where song was playing with visualiser the visualiser is gone. I am aware that LineBarVisualizer uses audiosessionid fr effect to show up. I am even trying to save the audiosessionid in savedinstance and restoring on restoresavedinstance but it responds only to orientation change, not to activity change

`public int getAudioId() {
if (mBound) {
if (mediaPlayer != null) {
audioId = mService.getAudioId();
}
}
return audioId;
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt("savedAudioID", getAudioId());

}

@Override
protected void onRestoreInstanceState(Bundle superState) {
    super.onRestoreInstanceState(superState);

    lineBarVisualizer.setPlayer(superState.getInt("savedAudioID"));

}

`

squareBarVisualizer.setPlayer(0) is not happening

I want to set the player to 0 so whenever the music is played, the visualizer animation occurs. But it's not happening, my app is crashing.

Crash:
java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3

Need the solution ASAP !!

Thankyou so much, looking forward to reply's

the error meassage:E/AudioEffect: set(): AudioFlinger could not create effect, status: -1 04-17 21:49:09.967 24849-24849/? E/visualizers-JNI: Visualizer initCheck failed E/Visualizer-JAVA: Error code -3 when initializing Visualizer.

public class MonitorSoundFragment extends Fragment {

    private static final String TAG = "MonitorSoundFragment.class";

    private BarVisualizer envirnment_bar;

    public static MonitorSoundFragment newIntance() {
        return new MonitorSoundFragment();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_monitor_sound, null);
        findViews(view);
        return view;
    }

    private void findViews(View view) {
        envirnment_bar = view.findViewById(R.id.environment_shower);
        envirnment_bar.setDensity(70);
        envirnment_bar.setColor(R.color.colorAccent);
        //获取AudioManager
        AudioManager audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
        envirnment_bar.setPlayer(audioManager.generateAudioSessionId());
        int volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        Log.i(TAG, "current volume" + volume);
    }
}

this is my code, I find the parameter is int audioSessionId,So I used this method of audiomanager, but it doesn't seem feasible

issue

java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3

no customization avaiable

hi thanks for making this but how can i customize the visualizers?
for example i want to change the max/min height of circle bar visualizer.

Cannot make it to work with tts

Is it possible to use the visualizer with Android text-to-speech?

My app uses Android text-to-speech to read paragraphs, and I'd like to add an audio visualizer so to have an animation according to the speech.

I find this audio visualizer very interesting, but I don't know how to use it with tts.

In the page examples it says you have to instantiate Media player, and shows this example:

mediaPlayer = MediaPlayer.create(this, R.raw.you_music);

But the fact is I'm not using MediaPlayer, but TTS for the audio. The library requires an audiosessionid to be passed to the player this way:

lineVisualizer.setPlayer(mediaPlayer.getAudioSessionId());

But I'm not finding any way to get the audiosessionid from tts, and inspected all the properties of the TextToSpeech instance, but no getAudioSessionId() or similar is present.

private lateinit var ttobj: TextToSpeech
    
    ttobj = TextToSpeech(this, this)
    ttobj.setLanguage(Locale.US)
    
    ttobj.setOnUtteranceProgressListener(object : UtteranceProgressListener() {
        override fun onStart(utteranceId: String) {
            //Here I would call setPlayer and pass an audiosessonid to start the visualizer.
        }
    
        override fun onDone(utteranceId: String) {
            runOnUiThread {
                ttsSpeechFinished()
            }
        }
    
        override fun onError(utteranceId: String) {
            Log.i("TextToSpeech", "On Error")
        }
    })
    
    fun doSpeech(){
        if (ttsStatus == TextToSpeech.SUCCESS){
            ttobj.speak("I'm going to read a paragraph for testing, right?", TextToSpeech.QUEUE_FLUSH, null,"")
        }
    }

The speech is working great, but I don't know how to "attach" the audio visualizer to the current tts audio sinthesys.

I've tried using AudioManager, that has a generateAudioSessionId() method:

var mAudioManager = activity?.getSystemService(AUDIO_SERVICE) as AudioManager
    val audioSessionId = mAudioManager.generateAudioSessionId()

But this audioSessionId is not working, and I'm obviously not sure I'm in the right direction.

Any help?

Xamarin?

Will there be any demo for Xamarin Android?

Got it working in a service

Hi I don't know if it is the correct way but I have the "line visualizer" working with a service. It does leave a line where the visualizer is located on the MainActivity when service is stopped. The line remains when a new animation starts. I will post the fix for that when I get it sorted.

  1. Create new java class
    public class Delegate { static MainActivity theMainActivity; }
    Then add this to your main activity in onCreate
    Delegate.theMainActivity = this;
    Finally add the visualizer code to your service
    ` public int onStartCommand(Intent intent, int flags, int startId) {

     ///////////
     LineVisualizer lineVisualizer = Delegate.theMainActivity.findViewById(R.id.visualizer);
     lineVisualizer.clearAnimation();
     lineVisualizer.setColor(ContextCompat.getColor(this, R.color.green));
     lineVisualizer.setStrokeWidth(1);
     lineVisualizer.clearAnimation();
     ///////////////
    
     String stUrl = intent.getStringExtra("URL");
     Uri uri =  Uri.parse( stUrl );
    
     player = MediaPlayer.create(this, uri);
     player.start();
     
     /////
     lineVisualizer.setPlayer(player);
     /////
     return Service.START_STICKY;
    

    }`

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException

in API level 16 i receive this exception
Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=49; index=49 at com.chibde.visualizer.BarVisualizer.onDraw + 85(BarVisualizer.java:85) at android.view.View.draw + 13458(View.java:13458) at android.view.View.getDisplayList + 12409(View.java:12409) at android.view.View.getDisplayList + 12453(View.java:12453) at android.view.ViewGroup.dispatchGetDisplayList + 2911(ViewGroup.java:2911) at android.view.View.getDisplayList + 12345(View.java:12345) at android.view.View.getDisplayList + 12453(View.java:12453)

fix : setCaptureSize() called in wrong state: 2

i use CircleBarVisualizer in my music app and when i use setPlayer(AudioSession) method the app crashes
for fix this problem in BaseVisualizer.java$setPlayer(int audioSessionId) method after make a new visualizer add this line:

visualizer.setEnabled(false);

and the bug fixed :)

How to resolve issue setCaptureSize() called in wrong state: 2?

Dear All,

I am doing music app, it is working fine when music play first time & linearbarvisualizer set media sessionid. I switch to another activity, music play in background & come to main activity linearbarvisualizer not showing. And i set media sessionid which is stored in sharedpreference, the error comes

Application crash & get error

<Caused by java.lang.IllegalStateException: setCaptureSize() called in wrong state: 2>

I have set linearbarvisualize enabled false but still get issue.

Visualizer Stop Playing when Call second time in a project

My Scenario is that I have two fragment
1st Fragment Show All Audios
2nd Fragment Show Recently Played Audios

Visualizer Show on Both Fragments of the recycler view Position of the currently playing item

` public void enableVisulizer(BarVisualizer barVisualizer) {

    barVisualizer.setVisibility(View.VISIBLE);
    barVisualizer.setColor(context.getResources().getColor(R.color.equalizerAnimatedColor));
    barVisualizer.setDensity(20);
    barVisualizer.setPlayer(PlayerService.exoPlayerSessionID);
}` 

This method is called the first time, then starts the visualizer, while calling from another fragment to start the visualizer at that position, then the visualizer gets stuck at the first position (stops playback).

Update wiki for various classes

For the Bar Visualizer
Usage
<com.chibde.visualizer.BarVisualizer android:id="@+id/visualizer" android:layout_width="match_parent" android:layout_height="250dp"/>

For the Circle Bar Visualizer
Usage
<com.chibde.visualizer.CircleBarVisualizer android:id="@+id/visualizer" android:layout_width="match_parent" android:layout_height="250dp"/>

For the Circle Visualizer
Usage
<com.chibde.visualizer.CircleVisualizer android:id="@+id/visualizer" android:layout_width="match_parent" android:layout_height="match_parent"/>
(Also missing > at the end)

For the Line Bar Visualizer
Usage
<com.chibde.visualizer.LineBarVisualizer android:id="@+id/visualizer" android:layout_width="match_parent" android:layout_height="250dp"/>

For the Line Visualizer
Usage
<com.chibde.visualizer.LineVisualizer android:id="@+id/visualizer" android:layout_width="match_parent" android:layout_height="250dp"/>

However the final SquareBar Visualizer has the correct usage case.

Cannot Initialize Visualizer Engine

Hi,

I followed the Wiki, but I still got this error.

Caused by: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3 at android.media.audiofx.Visualizer.<init>(Visualizer.java:218)

Provide ma method to clear the Visualizer

It would be nice to have a method to clear artifacts from the Visualizer.
This might be used in stations where you might use the android-audio-visualizer layout again in the same activity

It's unfortunate i got the same error, has anyone solved this anyway... i got <br>

          It's unfortunate i got the same error, has anyone solved this anyway... i got <br>

2021-06-18 19:11:54.504 24961-24961/com.bigger.bb E/AudioEffect: set(): AudioFlinger could not create effect e46b26a0-dddd-11db-8afd-0002a5d5c51b / �$���5�, status: -1 2021-06-18 19:11:54.504 24961-24961/com.bigger.bb E/visualizers-JNI: Visualizer initCheck failed -3 2021-06-18 19:11:54.505 24961-24961/com.bigger.bb E/Visualizer-JAVA: Error code -3 when initializing Visualizer. 2021-06-18 19:11:54.506 24961-24961/com.bigger.bb D/AndroidRuntime: Shutting down VM 2021-06-18 19:11:54.515 24961-24961/com.bigger.bb E/AndroidRuntime: FATAL EXCEPTION: main Process: com.bigger.bb, PID: 24961 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bigger.bb/com.bigger.bb.MainActivity}: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2819) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1623) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6548) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:451) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888) Caused by: java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3 at android.media.audiofx.Visualizer.<init>(Visualizer.java:218) at com.bigger.bb.MainActivity.setupVisualizerFxAndUI(MainActivity.java:330) at com.bigger.bb.MainActivity.initView(MainActivity.java:145) at com.bigger.bb.MainActivity.onCreate(MainActivity.java:115) at android.app.Activity.performCreate(Activity.java:7044) at android.app.Activity.performCreate(Activity.java:7035) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2772) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1623)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6548)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:451)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888) 

Originally posted by @daves254 in #9 (comment)

java.lang.RuntimeException: Cannot initialize Visualizer engine, error: -3

public void setPlayer(int audioSessionId) {

    visualizer = new Visualizer(audioSessionId);
    visualizer.setEnabled(false);
    visualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);


    visualizer.setDataCaptureListener(new Visualizer.OnDataCaptureListener() {
        @Override
        public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes,
                                          int samplingRate) {
            BaseVisualizer.this.bytes = bytes;
            invalidate();
        }

        @Override
        public void onFftDataCapture(Visualizer visualizer, byte[] bytes,
                                     int samplingRate) {
        }
    }, Visualizer.getMaxCaptureRate() / 2, true, false);

    visualizer.setEnabled(true);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.