├── .gitignore ├── .idea ├── assetWizardSettings.xml ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── .travis.yml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── gauravk │ │ └── audiovisualizersample │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ │ └── com │ │ │ └── gauravk │ │ │ └── audiovisualizersample │ │ │ ├── ui │ │ │ ├── BarActivity.java │ │ │ ├── BlastActivity.java │ │ │ ├── BlobActivity.java │ │ │ ├── CircleLineActivity.java │ │ │ ├── HiFiActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── MusicStreamActivity.java │ │ │ └── WaveActivity.java │ │ │ └── utils │ │ │ └── AudioPlayer.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ ├── pausebtn.xml │ │ └── playbtn.xml │ │ ├── layout │ │ ├── activity_bar.xml │ │ ├── activity_blast.xml │ │ ├── activity_blob.xml │ │ ├── activity_circle_line.xml │ │ ├── activity_hi_fi.xml │ │ ├── activity_main.xml │ │ ├── activity_music_stream.xml │ │ └── activity_wave.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── raw │ │ └── sample.aac │ │ └── values │ │ ├── colors.xml │ │ ├── ic_launcher_background.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── gauravk │ └── audiovisualizersample │ └── ExampleUnitTest.java ├── audiovisualizer ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── gauravk │ │ └── audiovisualizer │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── gauravk │ │ │ └── audiovisualizer │ │ │ ├── base │ │ │ └── BaseVisualizer.java │ │ │ ├── model │ │ │ ├── AnimSpeed.java │ │ │ ├── PaintStyle.java │ │ │ └── PositionGravity.java │ │ │ ├── utils │ │ │ ├── AVConstants.java │ │ │ └── BezierSpline.java │ │ │ └── visualizer │ │ │ ├── BarVisualizer.java │ │ │ ├── BlastVisualizer.java │ │ │ ├── BlobVisualizer.java │ │ │ ├── CircleLineVisualizer.java │ │ │ ├── HiFiVisualizer.java │ │ │ └── WaveVisualizer.java │ └── res │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── gauravk │ └── audiovisualizer │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties.ci ├── samplegif ├── bar_sample.gif ├── blast_sample.gif ├── blob_sample.gif ├── circle_line_sample.gif ├── hifi_sample.gif └── wave_sample.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/assetWizardSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 46 | 47 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gauravk95/audio-visualizer-android/df63b83ce5e162621f526cb917ab68a27873cd0b/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | 3 | # setup before install 4 | before_install: 5 | - echo yes | android update sdk --filter extra-android-support --no-ui --force > /dev/null 6 | - echo yes | android update sdk --filter extra-android-m2repository --no-ui --force > /dev/null 7 | - chmod +x ./gradlew 8 | - cp local.properties.ci local.properties 9 | 10 | # define android packages and licenses 11 | android: 12 | components: 13 | - tools 14 | - platform-tools 15 | - build-tools-28.0.3 16 | - android-28 17 | - extra-android-m2repository 18 | 19 | licenses: 20 | - android-sdk-license-.+ 21 | 22 | # only perform unit test only 23 | script: 24 | - ./gradlew assembleDebug -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Gaurav Kumar 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Audio Visualizer 2 | [![API](https://img.shields.io/badge/API-14%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=14) 3 | [![Download](https://api.bintray.com/packages/gauravk95/maven-repo/audiovisualizer/images/download.svg) ](https://bintray.com/gauravk95/maven-repo/audiovisualizer/_latestVersion) 4 | [![Build Status](https://travis-ci.org/gauravk95/audio-visualizer-android.svg?branch=master)](https://travis-ci.org/gauravk95/audio-visualizer-android) 5 | [![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-Gaurav%20Kumar-green.svg?style=flat )]( https://android-arsenal.com/details/1/7204 ) 6 | [![Android Weekly]( https://img.shields.io/badge/Android%20Weekly-%23352-blue.svg )]( http://androidweekly.net/issues/issue-352 ) 7 | 8 | A light-weight and easy-to-use Audio Visualizer for Android using the Android Canvas. 9 | 10 | ## Demos 11 | 12 | | CircleLine | Hifi | 13 | | ------------- |:-------------:| 14 | | ![CircleLine](https://raw.githubusercontent.com/gauravk95/audio-visualizer-android/master/samplegif/circle_line_sample.gif) |![Hifi](https://raw.githubusercontent.com/gauravk95/audio-visualizer-android/master/samplegif/hifi_sample.gif)| 15 | 16 | | Blob | Blast | 17 | | ------------- |:-------------:| 18 | | ![Blob](https://raw.githubusercontent.com/gauravk95/audio-visualizer-android/master/samplegif/blob_sample.gif) |![Blast](https://raw.githubusercontent.com/gauravk95/audio-visualizer-android/master/samplegif/blast_sample.gif)| 19 | 20 | | Wave | Bar | 21 | | ------------- |:-------------:| 22 | | ![Wave](https://raw.githubusercontent.com/gauravk95/audio-visualizer-android/master/samplegif/wave_sample.gif) |![Bar](https://raw.githubusercontent.com/gauravk95/audio-visualizer-android/master/samplegif/bar_sample.gif)| 23 | 24 | ## Available Visualizers: 25 | * **BlobVisualizer** - Gives blob like effect, good for low bpm audio 26 | * **BlastVisualizer** - Gives a blast like effect, very random, good for high bpm audio 27 | * **WaveVisualizer** - Gives a nice wave like effect, good for all kinds of audio 28 | * **BarVisualizer** - Gives the contemporary bar effect, good for all kinds of audio 29 | * **CircleLineVisualizer** - Gives the circular bar like effect, good for all kinds of audio 30 | * **HifiVisualizer** - Gives a unique circular wave like effect, good for all kinds of audio 31 | 32 | ## Usage 33 | 34 | **Note:** Use of the visualizer requires the permission `android.permission.RECORD_AUDIO` so add it to your manifest file. Also for Android 6.0 and above you will need request permission in runtime. 35 | 36 | Check out the Sample app, to see how its implemented. 37 | 38 | * This library is available on JCenter. To use it, add the following to `build.gradle` 39 | ```gradle 40 | dependencies { 41 | implementation 'com.gauravk.audiovisualizer:audiovisualizer:0.9.2' 42 | } 43 | ``` 44 | * Add the `com.gauravk.audiovisualizer.visualizer.BlastVisualizer` to your XML Layout file: 45 | ```xml 46 | 55 | ``` 56 | * Get the reference to this view in you Java Class 57 | ```java 58 | //get reference to visualizer 59 | mVisualizer = findViewById(R.id.blast); 60 | 61 | //TODO: init MediaPlayer and play the audio 62 | 63 | //get the AudioSessionId from your MediaPlayer and pass it to the visualizer 64 | int audioSessionId = mAudioPlayer.getAudioSessionId(); 65 | if (audioSessionId != -1) 66 | mVisualizer.setAudioSessionId(audioSessionId); 67 | 68 | ``` 69 | *Alternatively*, you can pass the raw audio bytes to the visualizer 70 | ```java 71 | //get reference to visualizer 72 | mVisualizer = findViewById(R.id.blast); 73 | 74 | //TODO: get the raw audio bytes 75 | 76 | //pass the bytes to visualizer 77 | mVisualizer.setRawAudioBytes(bytes); 78 | ``` 79 | **Now**, release the visualizer in your `onDestroy() or onStop()` 80 | ```java 81 | @Override 82 | protected void onDestroy() { 83 | super.onDestroy(); 84 | if (mVisualizer != null) 85 | mVisualizer.release(); 86 | } 87 | ``` 88 | If you want to hide the view upon completion of the audio, use 89 | ```java 90 | //TODO: check for completion of audio eg. using MediaPlayer.OnCompletionListener() 91 | if (mVisualizer != null) 92 | mVisualizer.hide(); 93 | ``` 94 | 95 | ### Similarly, include other visualizer 96 | 97 | ## Attributes 98 | | **attr** | **Description** | 99 | | ------------- | ------------- | 100 | | avType | Changes the Visualization type - **outline** or **fill**. (N/A for Bar Visualizer) | 101 | | avColor | Defines the color that is used in the visualizer | 102 | | avDensity | Sets the density of the visualization between `(0,1)` | 103 | | avSpeed | Defines the speed of the animation - **slow**, **medium** and **fast** | 104 | | avGravity | Updates position of the visualizers - **top** and **bottom** (N/A for Blob and Blast Visualizers) | 105 | | avWidth | Describes the width of the line if `avType is outline`, in case of Bar Visualizer, defines width of the bar | 106 | 107 | ## Contribute 108 | 109 | Found a bug or have an idea/feature request or any other help needed. Please suggest or report them [here](https://github.com/gauravk95/audio-visualizer-android/issues) 110 | 111 | I am always open to new suggestions and good contributions. 112 | 113 | Thanks to [@wangfengye](https://github.com/wangfengye) for **CircleLineVisualizer** and **HifiVisualizer**. 114 | 115 | ## License: 116 | ``` 117 | Copyright 2018 Gaurav Kumar 118 | 119 | Licensed under the Apache License, Version 2.0 (the "License"); 120 | you may not use this file except in compliance with the License. 121 | You may obtain a copy of the License at 122 | 123 | http://www.apache.org/licenses/LICENSE-2.0 124 | 125 | Unless required by applicable law or agreed to in writing, software 126 | distributed under the License is distributed on an "AS IS" BASIS, 127 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128 | See the License for the specific language governing permissions and 129 | limitations under the License. 130 | ``` 131 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.compileSdkVersion 5 | defaultConfig { 6 | applicationId "com.gauravk.audiovisualizersample" 7 | minSdkVersion rootProject.ext.minSdkVersion 8 | targetSdkVersion rootProject.ext.targetSdkVersion 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.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 | //support dependencies 24 | implementation "com.android.support:design:$supportLibraryVersion" 25 | implementation "com.android.support:appcompat-v7:$supportLibraryVersion" 26 | implementation "com.android.support:support-v4:$supportLibraryVersion" 27 | implementation "com.android.support.constraint:constraint-layout:$constraintLayoutVersion" 28 | 29 | //test dependencies 30 | testImplementation "junit:junit:$jUnitVersion" 31 | androidTestImplementation "com.android.support.test:runner:$testRunnerVersion" 32 | androidTestImplementation "com.android.support.test.espresso:espresso-core:$expressoVersion" 33 | 34 | //other module dependencies 35 | implementation project(':audiovisualizer') 36 | } 37 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/gauravk/audiovisualizersample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.gauravk.audiovisualizersample; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented 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() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.gauravk.audiovisualizersample", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gauravk95/audio-visualizer-android/df63b83ce5e162621f526cb917ab68a27873cd0b/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/com/gauravk/audiovisualizersample/ui/BarActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Gaurav Kumar 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.gauravk.audiovisualizersample.ui; 17 | 18 | import android.support.v7.app.AppCompatActivity; 19 | import android.os.Bundle; 20 | 21 | import com.gauravk.audiovisualizersample.R; 22 | import com.gauravk.audiovisualizersample.utils.AudioPlayer; 23 | import com.gauravk.audiovisualizer.visualizer.BarVisualizer; 24 | 25 | public class BarActivity extends AppCompatActivity { 26 | 27 | private BarVisualizer mVisualizer; 28 | 29 | private AudioPlayer mAudioPlayer; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_bar); 35 | 36 | mVisualizer = findViewById(R.id.bar); 37 | mAudioPlayer = new AudioPlayer(); 38 | } 39 | 40 | @Override 41 | protected void onStart() { 42 | super.onStart(); 43 | startPlayingAudio(R.raw.sample); 44 | } 45 | 46 | @Override 47 | protected void onStop() { 48 | super.onStop(); 49 | stopPlayingAudio(); 50 | } 51 | 52 | private void startPlayingAudio(int resId) { 53 | mAudioPlayer.play(this, resId, new AudioPlayer.AudioPlayerEvent() { 54 | @Override 55 | public void onCompleted() { 56 | if (mVisualizer != null) 57 | mVisualizer.hide(); 58 | } 59 | }); 60 | int audioSessionId = mAudioPlayer.getAudioSessionId(); 61 | if (audioSessionId != -1) 62 | mVisualizer.setAudioSessionId(audioSessionId); 63 | } 64 | 65 | private void stopPlayingAudio() { 66 | if (mAudioPlayer != null) 67 | mAudioPlayer.stop(); 68 | if (mVisualizer != null) 69 | mVisualizer.release(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/com/gauravk/audiovisualizersample/ui/BlastActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Gaurav Kumar 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.gauravk.audiovisualizersample.ui; 17 | 18 | import android.support.v7.app.AppCompatActivity; 19 | import android.os.Bundle; 20 | 21 | import com.gauravk.audiovisualizersample.R; 22 | import com.gauravk.audiovisualizersample.utils.AudioPlayer; 23 | import com.gauravk.audiovisualizer.visualizer.BlastVisualizer; 24 | 25 | public class BlastActivity extends AppCompatActivity { 26 | 27 | private BlastVisualizer mVisualizer; 28 | 29 | private AudioPlayer mAudioPlayer; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_blast); 35 | 36 | mVisualizer = findViewById(R.id.blast); 37 | mAudioPlayer = new AudioPlayer(); 38 | } 39 | 40 | @Override 41 | protected void onStart() { 42 | super.onStart(); 43 | startPlayingAudio(R.raw.sample); 44 | } 45 | 46 | @Override 47 | protected void onStop() { 48 | super.onStop(); 49 | stopPlayingAudio(); 50 | } 51 | 52 | private void startPlayingAudio(int resId) { 53 | mAudioPlayer.play(this, resId, new AudioPlayer.AudioPlayerEvent() { 54 | @Override 55 | public void onCompleted() { 56 | if (mVisualizer != null) 57 | mVisualizer.hide(); 58 | } 59 | }); 60 | int audioSessionId = mAudioPlayer.getAudioSessionId(); 61 | if (audioSessionId != -1) 62 | mVisualizer.setAudioSessionId(audioSessionId); 63 | } 64 | 65 | private void stopPlayingAudio() { 66 | if (mAudioPlayer != null) 67 | mAudioPlayer.stop(); 68 | if (mVisualizer != null) 69 | mVisualizer.release(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/com/gauravk/audiovisualizersample/ui/BlobActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Gaurav Kumar 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.gauravk.audiovisualizersample.ui; 17 | 18 | import android.support.v7.app.AppCompatActivity; 19 | import android.os.Bundle; 20 | 21 | import com.gauravk.audiovisualizer.model.PaintStyle; 22 | import com.gauravk.audiovisualizersample.R; 23 | import com.gauravk.audiovisualizersample.utils.AudioPlayer; 24 | import com.gauravk.audiovisualizer.visualizer.BlobVisualizer; 25 | 26 | public class BlobActivity extends AppCompatActivity { 27 | 28 | private BlobVisualizer mVisualizer; 29 | 30 | private AudioPlayer mAudioPlayer; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_blob); 36 | 37 | mVisualizer = findViewById(R.id.blob); 38 | mAudioPlayer = new AudioPlayer(); 39 | } 40 | 41 | @Override 42 | protected void onStart() { 43 | super.onStart(); 44 | startPlayingAudio(R.raw.sample); 45 | } 46 | 47 | @Override 48 | protected void onStop() { 49 | super.onStop(); 50 | stopPlayingAudio(); 51 | } 52 | 53 | private void startPlayingAudio(int resId) { 54 | mAudioPlayer.play(this, resId, new AudioPlayer.AudioPlayerEvent() { 55 | @Override 56 | public void onCompleted() { 57 | if (mVisualizer != null) 58 | mVisualizer.hide(); 59 | } 60 | }); 61 | int audioSessionId = mAudioPlayer.getAudioSessionId(); 62 | if (audioSessionId != -1) 63 | mVisualizer.setAudioSessionId(audioSessionId); 64 | } 65 | 66 | private void stopPlayingAudio() { 67 | if (mAudioPlayer != null) 68 | mAudioPlayer.stop(); 69 | if (mVisualizer != null) 70 | mVisualizer.release(); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/com/gauravk/audiovisualizersample/ui/CircleLineActivity.java: -------------------------------------------------------------------------------- 1 | package com.gauravk.audiovisualizersample.ui; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import com.gauravk.audiovisualizer.model.PaintStyle; 8 | import com.gauravk.audiovisualizer.visualizer.CircleLineVisualizer; 9 | import com.gauravk.audiovisualizersample.R; 10 | import com.gauravk.audiovisualizersample.utils.AudioPlayer; 11 | 12 | public class CircleLineActivity extends AppCompatActivity { 13 | 14 | private AudioPlayer mAudioPlayer; 15 | private CircleLineVisualizer mVisualizer; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_circle_line); 21 | mVisualizer = findViewById(R.id.blob); 22 | mAudioPlayer = new AudioPlayer(); 23 | mVisualizer.setDrawLine(true); 24 | } 25 | @Override 26 | protected void onStart() { 27 | super.onStart(); 28 | 29 | startPlayingAudio(R.raw.sample); 30 | } 31 | 32 | @Override 33 | protected void onStop() { 34 | super.onStop(); 35 | stopPlayingAudio(); 36 | } 37 | 38 | private void startPlayingAudio(int resId) { 39 | mAudioPlayer.play(this, resId, new AudioPlayer.AudioPlayerEvent() { 40 | @Override 41 | public void onCompleted() { 42 | if (mVisualizer != null) 43 | mVisualizer.hide(); 44 | } 45 | }); 46 | int audioSessionId = mAudioPlayer.getAudioSessionId(); 47 | if (audioSessionId != -1) 48 | mVisualizer.setAudioSessionId(audioSessionId); 49 | } 50 | 51 | private void stopPlayingAudio() { 52 | if (mAudioPlayer != null) 53 | mAudioPlayer.stop(); 54 | if (mVisualizer != null) 55 | mVisualizer.release(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/gauravk/audiovisualizersample/ui/HiFiActivity.java: -------------------------------------------------------------------------------- 1 | package com.gauravk.audiovisualizersample.ui; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import com.gauravk.audiovisualizer.visualizer.CircleLineVisualizer; 7 | import com.gauravk.audiovisualizer.visualizer.HiFiVisualizer; 8 | import com.gauravk.audiovisualizersample.R; 9 | import com.gauravk.audiovisualizersample.utils.AudioPlayer; 10 | 11 | public class HiFiActivity extends AppCompatActivity { 12 | private AudioPlayer mAudioPlayer; 13 | private HiFiVisualizer mVisualizer; 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_hi_fi); 18 | mVisualizer = findViewById(R.id.hifi); 19 | mAudioPlayer = new AudioPlayer(); 20 | } 21 | @Override 22 | protected void onStart() { 23 | super.onStart(); 24 | 25 | startPlayingAudio(R.raw.sample); 26 | } 27 | 28 | @Override 29 | protected void onStop() { 30 | super.onStop(); 31 | stopPlayingAudio(); 32 | } 33 | 34 | private void startPlayingAudio(int resId) { 35 | mAudioPlayer.play(this, resId, new AudioPlayer.AudioPlayerEvent() { 36 | @Override 37 | public void onCompleted() { 38 | if (mVisualizer != null) 39 | mVisualizer.hide(); 40 | } 41 | }); 42 | int audioSessionId = mAudioPlayer.getAudioSessionId(); 43 | if (audioSessionId != -1) 44 | mVisualizer.setAudioSessionId(audioSessionId); 45 | } 46 | 47 | private void stopPlayingAudio() { 48 | if (mAudioPlayer != null) 49 | mAudioPlayer.stop(); 50 | if (mVisualizer != null) 51 | mVisualizer.release(); 52 | }} 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/gauravk/audiovisualizersample/ui/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Gaurav Kumar 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.gauravk.audiovisualizersample.ui; 17 | 18 | import android.Manifest; 19 | import android.content.Intent; 20 | import android.content.pm.PackageManager; 21 | import android.support.v4.app.ActivityCompat; 22 | import android.support.v7.app.AppCompatActivity; 23 | import android.os.Bundle; 24 | import android.view.View; 25 | 26 | import com.gauravk.audiovisualizer.visualizer.CircleLineVisualizer; 27 | import com.gauravk.audiovisualizer.visualizer.HiFiVisualizer; 28 | import com.gauravk.audiovisualizersample.R; 29 | 30 | public class MainActivity extends AppCompatActivity implements View.OnClickListener{ 31 | 32 | private static final int PERM_REQ_CODE = 23; 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_main); 38 | 39 | findViewById(R.id.v_blob_btn).setOnClickListener(this); 40 | findViewById(R.id.v_blast_btn).setOnClickListener(this); 41 | findViewById(R.id.v_wave_btn).setOnClickListener(this); 42 | findViewById(R.id.v_bar_btn).setOnClickListener(this); 43 | findViewById(R.id.v_stream_btn).setOnClickListener(this); 44 | findViewById(R.id.v_circle_line_btn).setOnClickListener(this); 45 | findViewById(R.id.v_hifi_btn).setOnClickListener(this); 46 | } 47 | 48 | @Override 49 | public void onClick(View view) { 50 | switch (view.getId()){ 51 | case R.id.v_blob_btn: 52 | if (checkAudioPermission()) 53 | launchBlobActivity(); 54 | else 55 | requestAudioPermission(); 56 | break; 57 | case R.id.v_blast_btn: 58 | if (checkAudioPermission()) 59 | launchBlastActivity(); 60 | else 61 | requestAudioPermission(); 62 | break; 63 | case R.id.v_wave_btn: 64 | if (checkAudioPermission()) 65 | launchWaveActivity(); 66 | else 67 | requestAudioPermission(); 68 | break; 69 | case R.id.v_bar_btn: 70 | if (checkAudioPermission()) 71 | launchSpikyWaveActivity(); 72 | else 73 | requestAudioPermission(); 74 | break; 75 | case R.id.v_stream_btn: 76 | if (checkAudioPermission()) 77 | launchMusicStreamActivity(); 78 | else 79 | requestAudioPermission(); 80 | break; 81 | case R.id.v_circle_line_btn: 82 | if (checkAudioPermission()){ 83 | launchCircleLinectivity(); 84 | } 85 | 86 | else 87 | requestAudioPermission(); 88 | break; 89 | case R.id.v_hifi_btn: 90 | if (checkAudioPermission()){ 91 | Intent intent = new Intent(MainActivity.this, HiFiActivity.class); 92 | startActivity(intent); 93 | } 94 | 95 | else 96 | requestAudioPermission(); 97 | break; 98 | } 99 | } 100 | 101 | private boolean checkAudioPermission() { 102 | return ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED; 103 | } 104 | 105 | private void requestAudioPermission() { 106 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, PERM_REQ_CODE); 107 | } 108 | 109 | private void launchBlobActivity() { 110 | Intent intent = new Intent(MainActivity.this, BlobActivity.class); 111 | startActivity(intent); 112 | } 113 | 114 | private void launchBlastActivity() { 115 | Intent intent = new Intent(MainActivity.this, BlastActivity.class); 116 | startActivity(intent); 117 | } 118 | 119 | private void launchWaveActivity() { 120 | Intent intent = new Intent(MainActivity.this, WaveActivity.class); 121 | startActivity(intent); 122 | } 123 | 124 | private void launchSpikyWaveActivity() { 125 | Intent intent = new Intent(MainActivity.this, BarActivity.class); 126 | startActivity(intent); 127 | } 128 | 129 | private void launchMusicStreamActivity() { 130 | Intent intent = new Intent(MainActivity.this, MusicStreamActivity.class); 131 | startActivity(intent); 132 | } 133 | private void launchCircleLinectivity() { 134 | Intent intent = new Intent(MainActivity.this, CircleLineActivity.class); 135 | startActivity(intent); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /app/src/main/java/com/gauravk/audiovisualizersample/ui/MusicStreamActivity.java: -------------------------------------------------------------------------------- 1 | package com.gauravk.audiovisualizersample.ui; 2 | 3 | import android.app.ProgressDialog; 4 | import android.media.AudioManager; 5 | import android.media.MediaPlayer; 6 | import android.os.AsyncTask; 7 | import android.os.Bundle; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.view.View; 10 | import android.widget.ImageButton; 11 | 12 | import com.gauravk.audiovisualizer.visualizer.BlastVisualizer; 13 | import com.gauravk.audiovisualizersample.R; 14 | 15 | import java.io.IOException; 16 | 17 | public class MusicStreamActivity extends AppCompatActivity { 18 | 19 | ImageButton imgButton; 20 | BlastVisualizer mVisualizer; 21 | MediaPlayer mediaPlayer; 22 | 23 | String stream = "http://stream.radioreklama.bg/radio1rock128"; 24 | 25 | boolean prepared = false; 26 | boolean started = false; 27 | private ProgressDialog progressDialog; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_music_stream); 33 | 34 | imgButton = findViewById(R.id.playbtn); 35 | imgButton.setImageResource(R.drawable.playbtn); 36 | mVisualizer = findViewById(R.id.blast); 37 | 38 | mediaPlayer = new MediaPlayer(); 39 | mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 40 | 41 | int audioSessionId = mediaPlayer.getAudioSessionId(); 42 | if (audioSessionId != AudioManager.ERROR) { 43 | mVisualizer.setAudioSessionId(mediaPlayer.getAudioSessionId()); 44 | } 45 | 46 | progressDialog = new ProgressDialog(this); 47 | progressDialog.setMessage("Loading..."); 48 | progressDialog.show(); 49 | 50 | new PlayerTask().execute(stream); 51 | 52 | imgButton.setOnClickListener(new View.OnClickListener() { 53 | @Override 54 | public void onClick(View v) { 55 | if (started) { 56 | started = false; 57 | mediaPlayer.pause(); 58 | imgButton.setImageResource(R.drawable.playbtn); 59 | } else { 60 | started = true; 61 | mediaPlayer.start(); 62 | mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 63 | public void onPrepared(MediaPlayer mp) { 64 | mp.start(); 65 | } 66 | }); 67 | imgButton.setImageResource(R.drawable.pausebtn); 68 | } 69 | } 70 | }); 71 | } 72 | 73 | class PlayerTask extends AsyncTask { 74 | @Override 75 | protected Boolean doInBackground(String... strings) { 76 | 77 | try { 78 | mediaPlayer.setDataSource(strings[0]); 79 | mediaPlayer.prepare(); 80 | prepared = true; 81 | } catch (IOException e) { 82 | e.printStackTrace(); 83 | } 84 | return prepared; 85 | } 86 | 87 | @Override 88 | protected void onPostExecute(Boolean aBoolean) { 89 | super.onPostExecute(aBoolean); 90 | 91 | if (progressDialog.isShowing()) { 92 | progressDialog.cancel(); 93 | } 94 | imgButton.setImageResource(R.drawable.playbtn); 95 | } 96 | } 97 | 98 | @Override 99 | protected void onPause() { 100 | super.onPause(); 101 | if (started) { 102 | mediaPlayer.pause(); 103 | } 104 | } 105 | 106 | @Override 107 | protected void onResume() { 108 | super.onResume(); 109 | if (started) { 110 | //mediaPlayer.start(); 111 | mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 112 | public void onPrepared(MediaPlayer mp) { 113 | mp.start(); 114 | } 115 | }); 116 | mediaPlayer.prepareAsync(); 117 | } 118 | } 119 | 120 | @Override 121 | protected void onDestroy() { 122 | super.onDestroy(); 123 | if (prepared) { 124 | mediaPlayer.release(); 125 | } 126 | if (mVisualizer != null) 127 | mVisualizer.release(); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/gauravk/audiovisualizersample/ui/WaveActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Gaurav Kumar 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.gauravk.audiovisualizersample.ui; 17 | 18 | import android.support.v7.app.AppCompatActivity; 19 | import android.os.Bundle; 20 | 21 | import com.gauravk.audiovisualizersample.R; 22 | import com.gauravk.audiovisualizersample.utils.AudioPlayer; 23 | import com.gauravk.audiovisualizer.visualizer.WaveVisualizer; 24 | 25 | public class WaveActivity extends AppCompatActivity { 26 | 27 | private WaveVisualizer mVisualizer; 28 | 29 | private AudioPlayer mAudioPlayer; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_wave); 35 | 36 | mVisualizer = findViewById(R.id.wave); 37 | mAudioPlayer = new AudioPlayer(); 38 | } 39 | 40 | @Override 41 | protected void onStart() { 42 | super.onStart(); 43 | startPlayingAudio(R.raw.sample); 44 | } 45 | 46 | @Override 47 | protected void onStop() { 48 | super.onStop(); 49 | stopPlayingAudio(); 50 | } 51 | 52 | private void startPlayingAudio(int resId) { 53 | mAudioPlayer.play(this, resId, new AudioPlayer.AudioPlayerEvent() { 54 | @Override 55 | public void onCompleted() { 56 | if (mVisualizer != null) 57 | mVisualizer.hide(); 58 | } 59 | }); 60 | int audioSessionId = mAudioPlayer.getAudioSessionId(); 61 | if (audioSessionId != -1) 62 | mVisualizer.setAudioSessionId(audioSessionId); 63 | } 64 | 65 | private void stopPlayingAudio() { 66 | if (mAudioPlayer != null) 67 | mAudioPlayer.stop(); 68 | if (mVisualizer != null) 69 | mVisualizer.release(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/com/gauravk/audiovisualizersample/utils/AudioPlayer.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Gaurav Kumar 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.gauravk.audiovisualizersample.utils; 17 | 18 | import android.content.Context; 19 | import android.media.MediaPlayer; 20 | 21 | public class AudioPlayer { 22 | 23 | private MediaPlayer mMediaPlayer; 24 | 25 | public void stop() { 26 | if (mMediaPlayer != null) { 27 | mMediaPlayer.release(); 28 | mMediaPlayer = null; 29 | } 30 | } 31 | 32 | public void play(Context c, int rid, final AudioPlayerEvent audioPlayerEvent) { 33 | stop(); 34 | 35 | mMediaPlayer = MediaPlayer.create(c, rid); 36 | mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 37 | @Override 38 | public void onCompletion(MediaPlayer mediaPlayer) { 39 | stop(); 40 | if (audioPlayerEvent != null) 41 | audioPlayerEvent.onCompleted(); 42 | } 43 | }); 44 | 45 | mMediaPlayer.start(); 46 | } 47 | 48 | public int getAudioSessionId() { 49 | if (mMediaPlayer == null) 50 | return -1; 51 | return mMediaPlayer.getAudioSessionId(); 52 | } 53 | 54 | public interface AudioPlayerEvent { 55 | void onCompleted(); 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/pausebtn.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/playbtn.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_blast.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_blob.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_circle_line.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_hi_fi.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 |