@@ -1026,27 +1026,6 @@ Java_org_nift4_gramophone_hificore_NativeTrack_getProxy(JNIEnv* env, jobject, jl
10261026 ALOGE (" getProxy: didn't find android/media/AudioTrack.deferred_connect(J)V" );
10271027 return nullptr ;
10281028 }
1029- jmethodID regPb = env->GetMethodID (at, " baseRegisterPlayer" , " (I)V" );
1030- if (regPb == nullptr ) {
1031- ALOGE (" getProxy: didn't find android/media/AudioTrack.baseRegisterPlayer(J)V" );
1032- return nullptr ;
1033- }
1034- jmethodID setId = env->GetMethodID (at, " native_setPlayerIId" , " (I)V" );
1035- if (setId == nullptr ) {
1036- ALOGW (" getProxy: didn't find android/media/AudioTrack.native_setPlayerIId(I)V" );
1037- if (android_get_device_api_level () >= 31 ) {
1038- return nullptr ; // throw
1039- }
1040- env->ExceptionClear ();
1041- }
1042- jfieldID id = env->GetFieldID (at, " mPlayerIId" , " I" );
1043- if (id == nullptr ) {
1044- ALOGW (" getProxy: didn't find android/media/AudioTrack.mPlayerIId int" );
1045- if (android_get_device_api_level () >= 31 ) {
1046- return nullptr ; // throw
1047- }
1048- env->ExceptionClear ();
1049- }
10501029 // creating with 0 and then using deferred_connect() skips PlayerBase registration, which
10511030 // allows us to do it ourselves, but with our real session ID (almost like a real AudioTrack).
10521031 // before N, PlayerBase didn't exist, so we don't have to do that anywhere else.
@@ -1058,11 +1037,34 @@ Java_org_nift4_gramophone_hificore_NativeTrack_getProxy(JNIEnv* env, jobject, jl
10581037 if (env->ExceptionCheck ()) {
10591038 return nullptr ;
10601039 }
1061- env->CallVoidMethod (proxy, regPb, sessionId);
1040+ if (android_get_device_api_level () >= 26 ) {
1041+ jmethodID regPb = android_get_device_api_level () >= 31 ?
1042+ env->GetMethodID (at, " baseRegisterPlayer" , " (I)V" ) :
1043+ env->GetMethodID (at, " baseRegisterPlayer" , " ()V" );
1044+ if (regPb == nullptr ) {
1045+ ALOGE (" getProxy: didn't find android/media/AudioTrack.baseRegisterPlayer()V" );
1046+ return nullptr ; // throw
1047+ }
1048+ if (android_get_device_api_level () >= 31 ) {
1049+ env->CallVoidMethod (proxy, regPb, sessionId);
1050+ } else {
1051+ env->CallVoidMethod (proxy, regPb);
1052+ }
1053+ }
10621054 if (env->ExceptionCheck ()) {
10631055 return nullptr ;
10641056 }
1065- if (setId != nullptr && id != nullptr ) {
1057+ if (android_get_device_api_level () >= 31 ) {
1058+ jmethodID setId = env->GetMethodID (at, " native_setPlayerIId" , " (I)V" );
1059+ if (setId == nullptr ) {
1060+ ALOGW (" getProxy: didn't find android/media/AudioTrack.native_setPlayerIId(I)V" );
1061+ return nullptr ; // throw
1062+ }
1063+ jfieldID id = env->GetFieldID (at, " mPlayerIId" , " I" );
1064+ if (id == nullptr ) {
1065+ ALOGW (" getProxy: didn't find android/media/AudioTrack.mPlayerIId int" );
1066+ return nullptr ; // throw
1067+ }
10661068 // Let's be a nice citizen and contribute to MediaMetrics.
10671069 jint playerId = env->GetIntField (proxy, id);
10681070 if (env->ExceptionCheck ()) {
0 commit comments