应用程序中的JNI DETECTED ERROR:CallObjectMethodV的返回类型与void android.media.AudioTrack.play()不匹配

时间:2017-11-20 13:33:10

标签: java android android-ndk java-native-interface jnienv

我正在尝试使用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检测错误:返回类型   CallObjectMethodV与void android.media.AudioTrack.play()

不匹配

当我执行代码

 mEnv->CallObjectMethod(mAudioTrack,AudioTrack_Play);

感谢您的帮助

1 个答案:

答案 0 :(得分:3)

替换这个:

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

有了这个:

import glob, os

PATH_TO_TEST_IMAGES_DIR = 'dir'
searchstr = os.path.join(PATH_TO_TEST_IMAGES_DIR, '*.jpg')
list_of_images = glob.glob(searchstr)