|
8 | 8 |
|
9 | 9 | #define SLEEP_TIME (16000) |
10 | 10 |
|
11 | | -FFAudioPlayer *audioPlayer; |
12 | | - |
13 | 11 | void fftCallback(JNIEnv *env, jobject thiz, jmethodID fft_method, int8_t *data, int size) { |
14 | 12 | jbyteArray dataArray = env->NewByteArray(size); |
15 | 13 | env->SetByteArrayRegion(dataArray, 0, size, data); |
16 | 14 | env->CallVoidMethod(thiz, fft_method, dataArray); |
17 | 15 | env->DeleteLocalRef(dataArray); |
18 | 16 | } |
19 | 17 |
|
20 | | -AUDIO_PLAYER_FUNC(void, play, jstring path) { |
| 18 | +AUDIO_PLAYER_FUNC(long, native_1init) { |
| 19 | + auto *audioPlayer = new FFAudioPlayer(); |
| 20 | + return (long)audioPlayer; |
| 21 | +} |
| 22 | + |
| 23 | +AUDIO_PLAYER_FUNC(void, native_1play, long context, jstring path, jstring filter) { |
21 | 24 | if (path == nullptr) |
22 | 25 | return; |
23 | 26 |
|
24 | 27 | int result = 0; |
25 | 28 | const char* native_path = env->GetStringUTFChars(path, JNI_FALSE); |
26 | | - audioPlayer = new FFAudioPlayer(); |
| 29 | + auto *audioPlayer = (FFAudioPlayer*) context; |
27 | 30 | // open stream, and init work |
28 | 31 | audioPlayer->open(native_path); |
29 | 32 | // init AudioTrack |
@@ -73,14 +76,16 @@ AUDIO_PLAYER_FUNC(void, play, jstring path) { |
73 | 76 | delete audioPlayer; |
74 | 77 | } |
75 | 78 |
|
76 | | -AUDIO_PLAYER_FUNC(void, again, jstring filter_jstr) { |
| 79 | +AUDIO_PLAYER_FUNC(void, native_1again, long context, jstring filter_jstr) { |
77 | 80 | if (!filter_jstr) return; |
| 81 | + auto *audioPlayer = (FFAudioPlayer*) context; |
78 | 82 | audioPlayer->setFilterAgain(true); |
79 | 83 | const char *desc = env->GetStringUTFChars(filter_jstr, nullptr); |
80 | 84 | audioPlayer->setFilterDesc(desc); |
81 | 85 | } |
82 | 86 |
|
83 | | -AUDIO_PLAYER_FUNC(void, release) { |
| 87 | +AUDIO_PLAYER_FUNC(void, native_1release, long context) { |
| 88 | + auto *audioPlayer = (FFAudioPlayer*) context; |
84 | 89 | audioPlayer->setExit(true); |
85 | 90 | } |
86 | 91 |
|
0 commit comments