Giter Club home page Giter Club logo

githubzjy / audiovisualizeview Goto Github PK

View Code? Open in Web Editor NEW
164.0 5.0 35.0 7.39 MB

🎵🎵🎵 许多音乐App上常见的音频可视化效果,读取音频数据并利用傅里叶转换成可视化的字节数据,再通过自定义View渲染而成。An audio visualization effect like many music app, read audio data and use Fourier transform to visual byte data, and then through custom view rendering.

Home Page: https://github.com/GitHubZJY/AudioVisualizeView

Java 100.00%
visualizer visualize-effect audio-visualizer mediaplayer

audiovisualizeview's Introduction

AudioVisualizeView

许多音乐App上常见的音频可视化效果,读取音频数据并利用傅里叶转换成可视化的字节数据,再通过自定义View渲染而成.
组件源码目录:https://github.com/GitHubZJY/AudioVisualizeView/tree/master/audiovisualize
demo目录:https://github.com/GitHubZJY/AudioVisualizeView/tree/master/app

特性

  1. 支持自定义可视化颜色
  2. 支持本地路径、url、raw的音频路径读取,或自定义外部MediaPlayer传入音频数据渲染
  3. 支持自定义频谱展示数目
  4. 支持多种可视化展示形式,包括圆形、水平、波浪、网状、粒子等
  5. 支持AndroidX

效果预览

如何使用

在项目根目录的build.gradle添加:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

在项目的build.gradle添加如下依赖:

implementation 'com.github.GitHubZJY:AudioVisualizeView:v1.0.0'

1.申请录音权限和读写权限

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

由于需要读取音频数据和音频文件,需要先动态申请所需的权限,例:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    int checkCallPhonePermission = ContextCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO);
    if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(activity, new String[]{permission}, requestCode);
    }
}

详情可参考本项目demo

2.在xml中引用

<com.zjy.audiovisualize.view.SingleVisualizeView
        android:id="@+id/audio_visualize_view"
        app:visualize_ratio="2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

3.在代码中初始化

public class SingleVisualizeActivity extends AppCompatActivity {

    private AudioVisualizeView vAudioVisualize;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single_visualize);

        vAudioVisualize = findViewById(R.id.audio_visualize_view);
        vAudioVisualize.doPlay(R.raw.sound);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (vAudioVisualize != null) {
           vAudioVisualize.release();
        }
    }
}

在需要播放的位置,调用 doPlay 方法,并传入对应的音频资源id或者音频文件路径,即可开始播放。 在页面销毁时记得调用release释放对应的音频资源,避免内存泄漏。

About Me

一个在奋斗路上的Android小生
欢迎关注简书: https://www.jianshu.com/u/4cb2688ddf31

audiovisualizeview's People

Contributors

githubzjy avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

audiovisualizeview's Issues

播放完成后内存溢出闪退

播放完成后内存溢出闪退

2021-04-20 15:45:40.219 31976-743/com.xing.newtv W/Adreno-GSL: <sharedmem_gpuobj_alloc:2736>: sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory
2021-04-20 15:45:40.220 31976-743/com.xing.newtv E/Adreno-GSL: <gsl_memory_alloc_pure:2604>: GSL MEM ERROR: kgsl_sharedmem_alloc ioctl failed.
2021-04-20 15:45:40.220 31976-743/com.xing.newtv W/Adreno-GSL: <sharedmem_gpuobj_alloc:2736>: sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory
2021-04-20 15:45:40.220 31976-743/com.xing.newtv E/Adreno-GSL: <gsl_memory_alloc_pure:2604>: GSL MEM ERROR: kgsl_sharedmem_alloc ioctl failed.
2021-04-20 15:45:40.220 31976-743/com.xing.newtv W/Adreno-GSL: <sharedmem_gpuobj_alloc:2736>: sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory
2021-04-20 15:45:40.220 31976-743/com.xing.newtv E/Adreno-GSL: <gsl_memory_alloc_pure:2604>: GSL MEM ERROR: kgsl_sharedmem_alloc ioctl failed.
2021-04-20 15:45:40.220 31976-743/com.xing.newtv W/Adreno-GSL: <sharedmem_gpuobj_alloc:2736>: sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory
2021-04-20 15:45:40.220 31976-743/com.xing.newtv E/Adreno-GSL: <gsl_memory_alloc_pure:2604>: GSL MEM ERROR: kgsl_sharedmem_alloc ioctl failed.
2021-04-20 15:45:40.220 31976-743/com.xing.newtv W/Adreno-GSL: <sharedmem_gpuobj_alloc:2736>: sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory
2021-04-20 15:45:40.220 31976-743/com.xing.newtv E/Adreno-GSL: <gsl_memory_alloc_pure:2604>: GSL MEM ERROR: kgsl_sharedmem_alloc ioctl failed.
2021-04-20 15:45:40.220 31976-743/com.xing.newtv E/OpenGLRenderer: GL error: Out of memory!
2021-04-20 15:45:40.221 31976-743/com.xing.newtv A/OpenGLRenderer: GL errors! frameworks/base/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp:127
2021-04-20 15:45:40.225 31976-743/com.xing.newtv W/libc: malloc(532480) failed: returning null pointer
2021-04-20 15:45:40.225 31976-743/com.xing.newtv E/libc++abi: terminating with uncaught exception of type St9bad_alloc: std::bad_alloc
2021-04-20 15:45:40.225 31976-743/com.xing.newtv A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 743 (RenderThread), pid 31976 (com.xing.newtv)

請教 `VisualizerHelper` 的 `onFftDataCapture` 程式碼片段

你好 因為近期也在研究這塊,網路上爬了很多資料

想請教在 VisualizerHelperonFftDataCapture 程式碼片段裡

為什麼只需要計算 mCount*2 的 magnitude 呢?

mCount*2 小於 fft.length / 2,那麼 mCount*2+1~fft.length/2 的資料就直接捨棄了嗎?

for (int i = 2; i < mCount *2;) {
    model[j] = (float) Math.hypot(fft[i], fft[i + 1]);
    i += 2;
    j++;
    model[j] = Math.abs(model[j]);
}

先說聲謝謝!這個 repo 幫助了我很多!

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

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

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.