gpt4 book ai didi

java - JNI 检测到应用程序错误 : the return type of CallObjectMethodV does not match void android. media.AudioTrack.play()

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:32 29 4
gpt4 key购买 nike

我正在尝试使用 AudioTrack 从 JNI 播放音频缓冲区

使用以下代码从 JNI 初始化 AudioTrack 对象

    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");

错误的申请

JNI DETECTED ERROR IN APPLICATION: the return type of CallObjectMethodV does not match void android.media.AudioTrack.play()

当我执行代码时

 mEnv->CallObjectMethod(mAudioTrack,AudioTrack_Play);

谢谢你的帮助

最佳答案

替换这个:

env->CallObjectMethod( mediaPlayer.GetRawObject(), setSurfaceMethodId, parms);

有了这个:

env->CallVoidMethod( mediaPlayer.GetRawObject(), setSurfaceMethodId, parms );

关于java - JNI 检测到应用程序错误 : the return type of CallObjectMethodV does not match void android. media.AudioTrack.play(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47393276/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com