Unable to retrieve AudioTrack pointer for write()

久未见 提交于 2019-12-04 07:32:04
user366584

It is a simple fix but might be an Android issue, please refer to my fix below

if (track != null && track.getState() != AudioTrack.STATE_UNINITIALIZED) {
    if (track.getPlayState() != AudioTrack.PLAYSTATE_STOPPED) {

        try{
            track.stop();
        }catch (IllegalStateException e)
        {
            e.printStackTrace();
        }

    }

    track.release();     
    am.setMode(AudioManager.MODE_NORMAL); 

    //track.release();
    //track = null;
}

and OnCreate

private AudioManager am;

am = (AudioManager)this.context.getSystemService(Context.AUDIO_SERVICE); 
am.setMode(AudioManager.MODE_NORMAL); 
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);

And always use AudioTrack in Thread as main thread will also hand your application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!