I am trying to play audio buffer from JNI with AudioTrack
Initilizing AudioTrack object from JNI with below code
jclass AudioTrack = mEnv->FindClass("android/media/AudioTrack");
jclass AudioFormat = mEnv->FindClass("android/media/AudioFormat");
jclass AudioManager = mEnv->FindClass("android/media/AudioManager");
jfieldID AudioFormat_ENCODING_PCM_16BIT = mEnv->GetStaticFieldID(AudioFormat, "ENCODING_PCM_16BIT", "I");
jint ENCODING_PCM_16BIT =mEnv->GetStaticIntField( AudioFormat, AudioFormat_ENCODING_PCM_16BIT);
jfieldID AudioFormat_CHANNEL_CONFIGURATION_MONO = mEnv->GetStaticFieldID(AudioFormat, "CHANNEL_CONFIGURATION_MONO", "I");
jint CHANNEL_CONFIGURATION_MONO =mEnv->GetStaticIntField( AudioFormat, AudioFormat_CHANNEL_CONFIGURATION_MONO);
getMinBufferSize = mEnv->GetStaticMethodID(AudioTrack,"getMinBufferSize","(III)I");
// int minBufferSize = AudioTrack.getMinBufferSize(8000,AudioFormat.CHANNEL_CONFIGURATION_MONO,AdioFormat.ENCODING_PCM_16BIT);
minBufferSize = mEnv->CallStaticIntMethod(AudioTrack,getMinBufferSize,8000,ENCODING_PCM_16BIT,CHANNEL_CONFIGURATION_MONO);
//AudioTrack at = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT, minBufferSize,AudioTrack.MODE_STREAM);
jfieldID AudioManager_STREAM_MUSIC = mEnv->GetStaticFieldID(AudioManager, "STREAM_MUSIC", "I");
jint STREAM_MUSIC = mEnv->GetStaticIntField( AudioManager, AudioManager_STREAM_MUSIC);
jfieldID AudioTrack_MODE_STREAM = mEnv->GetStaticFieldID(AudioTrack, "MODE_STREAM", "I");
jint MODE_STREAM = mEnv->GetStaticIntField( AudioTrack, AudioTrack_MODE_STREAM);
audioTrackConstructor = mEnv->GetMethodID(AudioTrack,"<init>","(IIIIII)V");
mAudioTrack = mEnv->NewObject(AudioTrack,audioTrackConstructor,STREAM_MUSIC,8000,CHANNEL_CONFIGURATION_MONO,ENCODING_PCM_16BIT,minBufferSize,MODE_STREAM);
AudioTrack_Play = mEnv->GetMethodID(AudioTrack,"play","()V");
AudioTrack_Stop = mEnv->GetMethodID(AudioTrack,"stop","()V");
AudioTrack_Write= mEnv->GetMethodID(AudioTrack,"write","([BII)I");
application with error
JNI DETECTED ERROR IN APPLICATION: the return type of CallObjectMethodV does not match void android.media.AudioTrack.play()
When i execute code
mEnv->CallObjectMethod(mAudioTrack,AudioTrack_Play);
Thanks for your help
replace this:
env->CallObjectMethod( mediaPlayer.GetRawObject(), setSurfaceMethodId, parms);
With this:
env->CallVoidMethod( mediaPlayer.GetRawObject(), setSurfaceMethodId, parms );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With