├── sample ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── raw │ │ │ │ └── red_e.mp3 │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── drawable │ │ │ │ ├── ic_play_red_48dp.xml │ │ │ │ ├── ic_pause_red_48dp.xml │ │ │ │ └── ic_replay_red_48dp.xml │ │ │ └── layout │ │ │ │ ├── activity_service_example.xml │ │ │ │ ├── activity_bar_visualizer.xml │ │ │ │ ├── activity_line_visualizer.xml │ │ │ │ ├── activity_circle_visualizer.xml │ │ │ │ ├── activity_square_bar_visualizer.xml │ │ │ │ ├── activity_circle_bar_visualizer.xml │ │ │ │ ├── activity_line_bar_visualizer.xml │ │ │ │ ├── layout_audio_buttons.xml │ │ │ │ └── activity_main.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── chibde │ │ │ │ └── audiovisualizer │ │ │ │ └── sample │ │ │ │ ├── visualizer │ │ │ │ ├── CircleBarVisualizerActivity.java │ │ │ │ ├── LineVisualizerActivity.java │ │ │ │ ├── BarVisualizerActivity.java │ │ │ │ ├── LineBarVisualizerActivity.java │ │ │ │ ├── SquareBarVisualizerActivity.java │ │ │ │ └── CircleVisualizerActivity.java │ │ │ │ ├── MediaPlayerService.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── BaseActivity.java │ │ │ │ └── ServiceExampleActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── chibde │ │ │ └── audiovisualizer │ │ │ └── sample │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── chibde │ │ └── audiovisualizer │ │ └── sample │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── audiovisualizer ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── chibde │ │ │ ├── visualizer │ │ │ ├── BlazingColorVisualizer.java │ │ │ ├── BarVisualizer.java │ │ │ ├── LineVisualizer.java │ │ │ ├── SquareBarVisualizer.java │ │ │ ├── CircleBarVisualizer.java │ │ │ ├── LineBarVisualizer.java │ │ │ ├── CircleVisualizer.java │ │ │ └── CircleBarVisualizerSmooth.java │ │ │ └── BaseVisualizer.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── chibde │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── chibde │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── gradle.properties ├── .circleci └── config.yml ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /audiovisualizer/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':audiovisualizer' 2 | -------------------------------------------------------------------------------- /audiovisualizer/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AudioVisulaizer 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sample/src/main/res/raw/red_e.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/raw/red_e.mp3 -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GautamChibde/android-audio-visualizer/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue May 25 12:18:18 IST 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /audiovisualizer/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #3F51B5 7 | #FFFFFF 8 | 9 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_play_red_48dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_pause_red_48dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_replay_red_48dp.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_service_example.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /audiovisualizer/src/test/java/com/chibde/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.chibde; 2 | 3 | import org.junit.Test; 4 | 5 | import static junit.framework.Assert.assertEquals; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void additionIsCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_bar_visualizer.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_line_visualizer.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_circle_visualizer.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_square_bar_visualizer.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/src/test/java/com/chibde/audiovisualizer/sample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.chibde.audiovisualizer.sample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.*~ 2 | local/ 3 | .idea/ 4 | *.log 5 | *.orig 6 | /build 7 | com_crashlytics_export_strings.xml 8 | local.properties 9 | gradle/ 10 | .gradle/ 11 | .signing/ 12 | .idea/libraries/ 13 | .idea/workspace.xml 14 | .idea/tasks.xml 15 | .idea/.name 16 | .idea/compiler.xml 17 | .idea/copyright/profiles_settings.xml 18 | .idea/encodings.xml 19 | .idea/misc.xml 20 | .idea/modules.xml 21 | .idea/scopes/scope_settings.xml 22 | .idea/vcs.xml 23 | *.iml 24 | .DS_Store 25 | .DS_Store? 26 | ._* 27 | .Spotlight-V100 28 | .Trashes 29 | ehthumbs.db 30 | Thumbs.db -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_circle_bar_visualizer.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_line_bar_visualizer.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AudioVisualizer 3 | Play Pause Button 4 | Replay Button 5 | Line Visualizer 6 | Bar Visualizer 7 | Circle Visualizer 8 | Circle Bar Visualizer 9 | Line Bar Visualizer 10 | Activity With Service 11 | Square Bar Visualizer 12 | 13 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | android.enableJetifier=true 13 | android.useAndroidX=true 14 | org.gradle.jvmargs=-Xmx1536m 15 | 16 | # When configured, Gradle will run in incubating parallel mode. 17 | # This option should only be used with decoupled projects. More details, visit 18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 19 | # org.gradle.parallel=true 20 | -------------------------------------------------------------------------------- /audiovisualizer/src/androidTest/java/com/chibde/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.chibde; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static junit.framework.Assert.assertEquals; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.chibde.audiovisulaizer.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/gautam/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /audiovisualizer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/gautam/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 33 5 | defaultConfig { 6 | applicationId "com.chibde.audiovisualizer.sample" 7 | minSdkVersion 19 8 | targetSdkVersion 33 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation project(':audiovisualizer') 24 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | implementation 'androidx.appcompat:appcompat:1.6.1' 28 | implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0' 29 | testImplementation 'junit:junit:4.13.2' 30 | } 31 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/layout_audio_buttons.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Summary 11 | 12 | 13 | ## Code to reproduce 14 | 15 | 16 | ## Android version 17 | 18 | 19 | 20 | ## Impacted devices 21 | 22 | 23 | ## Installation method 24 | 25 | 26 | ## SDK classes 27 | 28 | 29 | ## Video 30 | 34 | 35 | ## Other information 36 | 37 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/chibde/audiovisualizer/sample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.audiovisualizer.sample; 17 | 18 | import android.content.Context; 19 | import androidx.test.InstrumentationRegistry; 20 | import androidx.test.runner.AndroidJUnit4; 21 | 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | 25 | import static org.junit.Assert.*; 26 | 27 | /** 28 | * Instrumentation test, which will execute on an Android device. 29 | * 30 | * @see Testing documentation 31 | */ 32 | @RunWith(AndroidJUnit4.class) 33 | public class ExampleInstrumentedTest { 34 | @Test 35 | public void useAppContext() throws Exception { 36 | // Context of the app under test. 37 | Context appContext = InstrumentationRegistry.getTargetContext(); 38 | 39 | assertEquals("com.chibde.audiovisualizer.sample", appContext.getPackageName()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sample/src/main/java/com/chibde/audiovisualizer/sample/visualizer/CircleBarVisualizerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.audiovisualizer.sample.visualizer; 17 | 18 | import androidx.core.content.ContextCompat; 19 | import android.view.View; 20 | import android.widget.ImageButton; 21 | 22 | import com.chibde.audiovisualizer.sample.BaseActivity; 23 | import com.chibde.audiovisualizer.sample.R; 24 | import com.chibde.visualizer.CircleBarVisualizer; 25 | 26 | public class CircleBarVisualizerActivity extends BaseActivity { 27 | 28 | @Override 29 | protected void init() { 30 | CircleBarVisualizer circleBarVisualizer = findViewById(R.id.visualizer); 31 | circleBarVisualizer.setColor(ContextCompat.getColor(this, R.color.custom)); 32 | circleBarVisualizer.setPlayer(mediaPlayer.getAudioSessionId()); 33 | } 34 | 35 | public void replay(View view) { 36 | if (mediaPlayer != null) { 37 | mediaPlayer.seekTo(0); 38 | } 39 | } 40 | 41 | public void playPause(View view) { 42 | playPauseBtnClicked((ImageButton) view); 43 | } 44 | 45 | @Override 46 | protected int getLayout() { 47 | return R.layout.activity_circle_bar_visualizer; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sample/src/main/java/com/chibde/audiovisualizer/sample/visualizer/LineVisualizerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.audiovisualizer.sample.visualizer; 17 | 18 | import androidx.core.content.ContextCompat; 19 | import android.view.View; 20 | import android.widget.ImageButton; 21 | 22 | import com.chibde.audiovisualizer.sample.BaseActivity; 23 | import com.chibde.audiovisualizer.sample.R; 24 | import com.chibde.visualizer.LineVisualizer; 25 | 26 | public class LineVisualizerActivity extends BaseActivity { 27 | 28 | @Override 29 | protected void init() { 30 | LineVisualizer lineVisualizer = findViewById(R.id.visualizer); 31 | // set custom color to the line. 32 | lineVisualizer.setColor(ContextCompat.getColor(this, R.color.custom)); 33 | 34 | // set the line with for the visualizer between 1-10 default 1. 35 | lineVisualizer.setStrokeWidth(1); 36 | 37 | // Set you media player to the visualizer. 38 | lineVisualizer.setPlayer(mediaPlayer.getAudioSessionId()); 39 | } 40 | 41 | public void replay(View view) { 42 | if (mediaPlayer != null) { 43 | mediaPlayer.seekTo(0); 44 | } 45 | } 46 | 47 | public void playPause(View view) { 48 | playPauseBtnClicked((ImageButton) view); 49 | } 50 | 51 | @Override 52 | protected int getLayout() { 53 | return R.layout.activity_line_visualizer; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sample/src/main/java/com/chibde/audiovisualizer/sample/visualizer/BarVisualizerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.audiovisualizer.sample.visualizer; 17 | 18 | import androidx.core.content.ContextCompat; 19 | import android.view.View; 20 | import android.widget.ImageButton; 21 | 22 | import com.chibde.audiovisualizer.sample.BaseActivity; 23 | import com.chibde.audiovisualizer.sample.R; 24 | import com.chibde.visualizer.BarVisualizer; 25 | 26 | public class BarVisualizerActivity extends BaseActivity { 27 | 28 | @Override 29 | protected void init() { 30 | BarVisualizer barVisualizer = findViewById(R.id.visualizer); 31 | 32 | // set custom color to the line. 33 | barVisualizer.setColor(ContextCompat.getColor(this, R.color.custom)); 34 | 35 | // define custom number of bars you want in the visualizer between (10 - 256). 36 | barVisualizer.setDensity(70); 37 | 38 | // Set your media player to the visualizer. 39 | barVisualizer.setPlayer(mediaPlayer.getAudioSessionId()); 40 | } 41 | 42 | public void replay(View view) { 43 | if (mediaPlayer != null) { 44 | mediaPlayer.seekTo(0); 45 | } 46 | } 47 | 48 | public void playPause(View view) { 49 | playPauseBtnClicked((ImageButton) view); 50 | } 51 | 52 | @Override 53 | protected int getLayout() { 54 | return R.layout.activity_bar_visualizer; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sample/src/main/java/com/chibde/audiovisualizer/sample/visualizer/LineBarVisualizerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.audiovisualizer.sample.visualizer; 17 | 18 | import androidx.core.content.ContextCompat; 19 | import android.view.View; 20 | import android.widget.ImageButton; 21 | 22 | import com.chibde.audiovisualizer.sample.BaseActivity; 23 | import com.chibde.audiovisualizer.sample.R; 24 | import com.chibde.visualizer.LineBarVisualizer; 25 | 26 | public class LineBarVisualizerActivity extends BaseActivity { 27 | 28 | @Override 29 | protected void init() { 30 | LineBarVisualizer lineBarVisualizer = findViewById(R.id.visualizer); 31 | 32 | // set custom color to the line. 33 | lineBarVisualizer.setColor(ContextCompat.getColor(this, R.color.custom)); 34 | 35 | // define custom number of bars you want in the visualizer between (10 - 256). 36 | lineBarVisualizer.setDensity(90f); 37 | 38 | // Set your media player to the visualizer. 39 | lineBarVisualizer.setPlayer(mediaPlayer.getAudioSessionId()); 40 | } 41 | 42 | public void replay(View view) { 43 | if (mediaPlayer != null) { 44 | mediaPlayer.seekTo(0); 45 | } 46 | } 47 | 48 | public void playPause(View view) { 49 | playPauseBtnClicked((ImageButton) view); 50 | } 51 | 52 | @Override 53 | protected int getLayout() { 54 | return R.layout.activity_line_bar_visualizer; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sample/src/main/java/com/chibde/audiovisualizer/sample/visualizer/SquareBarVisualizerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.audiovisualizer.sample.visualizer; 17 | 18 | import android.view.View; 19 | import android.widget.ImageButton; 20 | 21 | import androidx.core.content.ContextCompat; 22 | 23 | import com.chibde.audiovisualizer.sample.BaseActivity; 24 | import com.chibde.audiovisualizer.sample.R; 25 | import com.chibde.visualizer.SquareBarVisualizer; 26 | 27 | public class SquareBarVisualizerActivity extends BaseActivity { 28 | 29 | @Override 30 | protected void init() { 31 | SquareBarVisualizer squareBarVisualizer = findViewById(R.id.visualizer); 32 | 33 | // set custom color to the line. 34 | squareBarVisualizer.setColor(ContextCompat.getColor(this, R.color.custom)); 35 | 36 | // define custom number of bars you want in the visualizer between (10 - 256). 37 | squareBarVisualizer.setDensity(65); 38 | 39 | // set Gap 40 | squareBarVisualizer.setGap(2); 41 | 42 | // Set your media player to the visualizer. 43 | squareBarVisualizer.setPlayer(mediaPlayer.getAudioSessionId()); 44 | } 45 | 46 | public void replay(View view) { 47 | if (mediaPlayer != null) { 48 | mediaPlayer.seekTo(0); 49 | } 50 | } 51 | 52 | public void playPause(View view) { 53 | playPauseBtnClicked((ImageButton) view); 54 | } 55 | 56 | @Override 57 | protected int getLayout() { 58 | return R.layout.activity_square_bar_visualizer; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sample/src/main/java/com/chibde/audiovisualizer/sample/visualizer/CircleVisualizerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.audiovisualizer.sample.visualizer; 17 | 18 | import androidx.core.content.ContextCompat; 19 | import android.view.View; 20 | import android.widget.ImageButton; 21 | 22 | import com.chibde.audiovisualizer.sample.BaseActivity; 23 | import com.chibde.audiovisualizer.sample.R; 24 | import com.chibde.visualizer.CircleVisualizer; 25 | 26 | public class CircleVisualizerActivity extends BaseActivity { 27 | 28 | @Override 29 | protected void init() { 30 | CircleVisualizer circleVisualizer = findViewById(R.id.visualizer); 31 | // set custom color to the line. 32 | circleVisualizer.setColor(ContextCompat.getColor(this, R.color.custom)); 33 | 34 | // Customize the size of the circle. by defalut multipliers is 1. 35 | circleVisualizer.setRadiusMultiplier(2f); 36 | 37 | // set the line with for the visualizer between 1-10 default 1. 38 | circleVisualizer.setStrokeWidth(1); 39 | 40 | // Set your media player to the visualizer. 41 | circleVisualizer.setPlayer(mediaPlayer.getAudioSessionId()); 42 | } 43 | 44 | public void replay(View view) { 45 | if (mediaPlayer != null) { 46 | mediaPlayer.seekTo(0); 47 | } 48 | } 49 | 50 | public void playPause(View view) { 51 | playPauseBtnClicked((ImageButton) view); 52 | } 53 | 54 | @Override 55 | protected int getLayout() { 56 | return R.layout.activity_circle_visualizer; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | orbs: 4 | android: circleci/android@1.0.3 5 | 6 | jobs: 7 | build-and-test: 8 | executor: 9 | name: android/android-machine 10 | 11 | steps: 12 | - checkout 13 | 14 | - android/run-tests: 15 | test-command: ./gradlew lint testDebug --continue 16 | 17 | - run: 18 | name: Assemble release build 19 | command: | 20 | ./gradlew assembleRelease 21 | 22 | build-verify: 23 | executor: 24 | name: android/android-machine 25 | steps: 26 | - checkout 27 | - run: 28 | name: Assemble release build 29 | command: | 30 | ./gradlew clean assemble 31 | 32 | deploy-to-sonatype: 33 | executor: 34 | name: android/android-machine 35 | resource-class: large 36 | steps: 37 | - checkout 38 | - run: 39 | name: Define ORG_GRADLE_PROJECT_LIBRARY_VERSION Environment Variable at Runtime 40 | command: | 41 | if [ $CIRCLE_TAG ] 42 | then 43 | echo 'export ORG_GRADLE_PROJECT_LIBRARY_VERSION=$CIRCLE_TAG' >> $BASH_ENV 44 | else 45 | echo "export ORG_GRADLE_PROJECT_LIBRARY_VERSION=`git tag | tail -1`-SNAPSHOT" >> $BASH_ENV 46 | fi 47 | source $BASH_ENV 48 | - run: 49 | name: Inject Maven signing key 50 | command: | 51 | echo $GPG_SIGNING_KEY \ 52 | | awk 'NR == 1 { print "SIGNING_KEY=" } 1' ORS='\\n' \ 53 | >> gradle.properties 54 | - run: 55 | name: Publish to Maven 56 | command: ./gradlew assemble publishToSonatype closeAndReleaseSonatypeStagingRepository 57 | 58 | workflows: 59 | build-test-deploy: 60 | jobs: 61 | - build-and-test 62 | - build-verify: 63 | name: build-test 64 | filters: 65 | tags: 66 | only: /^[0-9]+.*/ 67 | - hold-for-approval: 68 | type: approval 69 | requires: 70 | - build-test 71 | filters: 72 | tags: 73 | only: /^[0-9]+.*/ 74 | branches: 75 | ignore: /.*/ 76 | - deploy-to-sonatype: 77 | name: Deploy to Maven Central 78 | requires: 79 | - hold-for-approval 80 | filters: 81 | tags: 82 | only: /^[0-9]+.*/ 83 | -------------------------------------------------------------------------------- /audiovisualizer/src/main/java/com/chibde/visualizer/BlazingColorVisualizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.visualizer; 17 | 18 | import android.content.Context; 19 | import android.graphics.Canvas; 20 | import android.graphics.Color; 21 | import android.graphics.LinearGradient; 22 | import android.graphics.Shader; 23 | import androidx.annotation.Nullable; 24 | import android.util.AttributeSet; 25 | 26 | import com.chibde.BaseVisualizer; 27 | 28 | /** 29 | * TODO 30 | * 31 | * Created by gautam chibde on 29/10/17. 32 | */ 33 | 34 | class BlazingColorVisualizer extends BaseVisualizer { 35 | private Shader shader; 36 | 37 | public BlazingColorVisualizer(Context context) { 38 | super(context); 39 | } 40 | 41 | public BlazingColorVisualizer(Context context, 42 | @Nullable AttributeSet attrs) { 43 | super(context, attrs); 44 | } 45 | 46 | public BlazingColorVisualizer(Context context, 47 | @Nullable AttributeSet attrs, 48 | int defStyleAttr) { 49 | super(context, attrs, defStyleAttr); 50 | } 51 | 52 | @Override 53 | protected void init() { 54 | shader = new LinearGradient(0, 55 | 0, 56 | 0, 57 | getHeight(), 58 | Color.BLUE, 59 | Color.GREEN, 60 | Shader.TileMode.MIRROR /*or REPEAT*/); 61 | } 62 | 63 | @Override 64 | protected void onDraw(Canvas canvas) { 65 | if (bytes != null) { 66 | paint.setShader(shader); 67 | for (int i = 0, k = 0; i < (bytes.length - 1) && k < bytes.length; i++, k++) { 68 | int top = getHeight() + 69 | ((byte) (Math.abs(bytes[k]) + 128)) * getHeight() / 128; 70 | canvas.drawLine(i, getHeight(), i, top, paint); 71 | } 72 | super.onDraw(canvas); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /sample/src/main/java/com/chibde/audiovisualizer/sample/MediaPlayerService.java: -------------------------------------------------------------------------------- 1 | package com.chibde.audiovisualizer.sample; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.media.MediaPlayer; 6 | import android.os.Binder; 7 | import android.os.IBinder; 8 | import androidx.annotation.Nullable; 9 | import androidx.localbroadcastmanager.content.LocalBroadcastManager; 10 | 11 | public class MediaPlayerService extends Service { 12 | 13 | public static final String INTENT_FILTER = "MediaPlayerServiceIntentFilter"; 14 | public static final String INTENT_AUDIO_SESSION_ID = "intent_audio_session_id"; 15 | 16 | private IBinder mediaPlayerServiceBinder = new MediaPlayerServiceBinder(); 17 | private MediaPlayer mediaPlayer; 18 | 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | mediaPlayer = MediaPlayer.create(this, R.raw.red_e); 23 | mediaPlayer.setLooping(false); 24 | 25 | Intent intent = new Intent(INTENT_FILTER); //put the same message as in the filter you used in the activity when registering the receiver 26 | intent.putExtra(INTENT_AUDIO_SESSION_ID, mediaPlayer.getAudioSessionId()); 27 | // Send audio session id through 28 | LocalBroadcastManager.getInstance(this).sendBroadcast(intent); 29 | } 30 | 31 | @Nullable 32 | @Override 33 | public IBinder onBind(Intent intent) { 34 | return mediaPlayerServiceBinder; 35 | } 36 | 37 | public void replay() { 38 | if (mediaPlayer != null) { 39 | mediaPlayer.seekTo(0); 40 | } 41 | } 42 | 43 | @Override 44 | public void onRebind(Intent intent) { 45 | super.onRebind(intent); 46 | } 47 | 48 | @Override 49 | public boolean onUnbind(Intent intent) { 50 | return true; 51 | } 52 | 53 | @Override 54 | public void onDestroy() { 55 | super.onDestroy(); 56 | if (mediaPlayer != null) { 57 | mediaPlayer.release(); 58 | } 59 | } 60 | 61 | public boolean isPlaying() { 62 | return mediaPlayer != null && mediaPlayer.isPlaying(); 63 | } 64 | 65 | public void pause() { 66 | if (mediaPlayer != null) { 67 | mediaPlayer.pause(); 68 | } 69 | } 70 | 71 | public void start() { 72 | if (mediaPlayer != null) { 73 | mediaPlayer.start(); 74 | } 75 | } 76 | 77 | public class MediaPlayerServiceBinder extends Binder { 78 | MediaPlayerService getService() { 79 | return MediaPlayerService.this; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /sample/src/main/java/com/chibde/audiovisualizer/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.audiovisualizer.sample; 17 | 18 | import android.content.Intent; 19 | import android.os.Bundle; 20 | import androidx.appcompat.app.AppCompatActivity; 21 | import android.view.View; 22 | 23 | import com.chibde.audiovisualizer.sample.visualizer.BarVisualizerActivity; 24 | import com.chibde.audiovisualizer.sample.visualizer.CircleBarVisualizerActivity; 25 | import com.chibde.audiovisualizer.sample.visualizer.CircleVisualizerActivity; 26 | import com.chibde.audiovisualizer.sample.visualizer.LineBarVisualizerActivity; 27 | import com.chibde.audiovisualizer.sample.visualizer.LineVisualizerActivity; 28 | import com.chibde.audiovisualizer.sample.visualizer.SquareBarVisualizerActivity; 29 | import com.chibde.visualizer.SquareBarVisualizer; 30 | 31 | public class MainActivity extends AppCompatActivity { 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | } 37 | 38 | public void line(View view) { 39 | startActivity(LineVisualizerActivity.class); 40 | } 41 | 42 | public void bar(View view) { 43 | startActivity(BarVisualizerActivity.class); 44 | } 45 | 46 | public void circle(View view) { 47 | startActivity(CircleVisualizerActivity.class); 48 | } 49 | 50 | public void circleBar(View view) { 51 | startActivity(CircleBarVisualizerActivity.class); 52 | } 53 | 54 | public void lineBar(View view) { 55 | startActivity(LineBarVisualizerActivity.class); 56 | } 57 | 58 | public void service(View view) { 59 | startActivity(ServiceExampleActivity.class); 60 | } 61 | 62 | public void square(View view) { 63 | startActivity(SquareBarVisualizerActivity.class); 64 | } 65 | 66 | public void startActivity(Class clazz) { 67 | startActivity(new Intent(this, clazz)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /audiovisualizer/src/main/java/com/chibde/visualizer/BarVisualizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.visualizer; 17 | 18 | import android.content.Context; 19 | import android.graphics.Canvas; 20 | import android.graphics.Paint; 21 | import androidx.annotation.Nullable; 22 | import android.util.AttributeSet; 23 | 24 | import com.chibde.BaseVisualizer; 25 | 26 | /** 27 | * Custom view that creates a Bar visualizer effect for 28 | * the android {@link android.media.MediaPlayer} 29 | * 30 | * Created by gautam chibde on 28/10/17. 31 | */ 32 | 33 | public class BarVisualizer extends BaseVisualizer { 34 | 35 | private float density = 50; 36 | private int gap; 37 | 38 | public BarVisualizer(Context context) { 39 | super(context); 40 | } 41 | 42 | public BarVisualizer(Context context, 43 | @Nullable AttributeSet attrs) { 44 | super(context, attrs); 45 | } 46 | 47 | public BarVisualizer(Context context, 48 | @Nullable AttributeSet attrs, 49 | int defStyleAttr) { 50 | super(context, attrs, defStyleAttr); 51 | } 52 | 53 | @Override 54 | protected void init() { 55 | this.density = 50; 56 | this.gap = 4; 57 | paint.setStyle(Paint.Style.FILL); 58 | } 59 | 60 | /** 61 | * Sets the density to the Bar visualizer i.e the number of bars 62 | * to be displayed. Density can vary from 10 to 256. 63 | * by default the value is set to 50. 64 | * 65 | * @param density density of the bar visualizer 66 | */ 67 | public void setDensity(float density) { 68 | this.density = density; 69 | if (density > 256) { 70 | this.density = 256; 71 | } else if (density < 10) { 72 | this.density = 10; 73 | } 74 | } 75 | 76 | @Override 77 | protected void onDraw(Canvas canvas) { 78 | if (bytes != null) { 79 | float barWidth = getWidth() / density; 80 | float div = bytes.length / density; 81 | paint.setStrokeWidth(barWidth - gap); 82 | 83 | for (int i = 0; i < density; i++) { 84 | int bytePosition = (int) Math.ceil(i * div); 85 | int top = getHeight() + 86 | ((byte) (Math.abs(bytes[bytePosition]) + 128)) * getHeight() / 128; 87 | float barX = (i * barWidth) + (barWidth / 2); 88 | canvas.drawLine(barX, getHeight(), barX, top, paint); 89 | } 90 | super.onDraw(canvas); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /audiovisualizer/src/main/java/com/chibde/visualizer/LineVisualizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Gautam Chibde 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.chibde.visualizer; 17 | 18 | import android.content.Context; 19 | import android.graphics.Canvas; 20 | import android.graphics.Rect; 21 | import androidx.annotation.Nullable; 22 | import android.util.AttributeSet; 23 | 24 | import com.chibde.BaseVisualizer; 25 | 26 | /** 27 | * Custom view that creates a Bar visualizer effect for 28 | * the android {@link android.media.MediaPlayer} 29 | * 30 | * Created by gautam chibde on 28/10/17. 31 | */ 32 | 33 | public class LineVisualizer extends BaseVisualizer { 34 | private float[] points; 35 | private Rect rect = new Rect(); 36 | private float strokeWidth = 0.005f; 37 | 38 | public LineVisualizer(Context context) { 39 | super(context); 40 | } 41 | 42 | public LineVisualizer(Context context, 43 | @Nullable AttributeSet attrs) { 44 | super(context, attrs); 45 | } 46 | 47 | public LineVisualizer(Context context, 48 | @Nullable AttributeSet attrs, 49 | int defStyleAttr) { 50 | super(context, attrs, defStyleAttr); 51 | } 52 | 53 | @Override 54 | protected void init() { 55 | } 56 | 57 | /** 58 | * set Stroke width for your visualizer takes input between 1-10 59 | * 60 | * @param strokeWidth stroke width between 1-10 61 | */ 62 | public void setStrokeWidth(int strokeWidth) { 63 | if (strokeWidth > 10) { 64 | this.strokeWidth = 10 * 0.005f; 65 | } else if (strokeWidth < 1) { 66 | this.strokeWidth = 0.005f; 67 | } 68 | this.strokeWidth = strokeWidth * 0.005f; 69 | } 70 | 71 | @Override 72 | protected void onDraw(Canvas canvas) { 73 | if (bytes != null) { 74 | if (points == null || points.length < bytes.length * 4) { 75 | points = new float[bytes.length * 4]; 76 | } 77 | paint.setStrokeWidth(getHeight() * strokeWidth); 78 | rect.set(0, 0, getWidth(), getHeight()); 79 | 80 | for (int i = 0; i < bytes.length - 1; i++) { 81 | points[i * 4] = rect.width() * i / (bytes.length - 1); 82 | points[i * 4 + 1] = rect.height() / 2 83 | + ((byte) (bytes[i] + 128)) * (rect.height() / 3) / 128; 84 | points[i * 4 + 2] = rect.width() * (i + 1) / (bytes.length - 1); 85 | points[i * 4 + 3] = rect.height() / 2 86 | + ((byte) (bytes[i + 1] + 128)) * (rect.height() / 3) / 128; 87 | } 88 | canvas.drawLines(points, paint); 89 | } 90 | super.onDraw(canvas); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 32 | 33 | 37 | 40 | 41 | 45 | 49 | 52 | 53 | 57 | 60 | 61 | 62 | 66 | 67 | 70 | 71 | 72 | 75 | 76 | 77 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 |