如何在MediaPlayer上重复声音的每个循环运行回调方法? OnCompleteListener只运行一次。所以,我试过了,
MediaPlayer mp = MediaPlayer.create(context, R.raw.something);
public void play() {
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer paramMP) {
mp.start();
}
});
mp.start();
}
每个循环之间有延迟。所以,我试图让我自己的MediaPlayer自己使用OpenSLES(NDK)。但是,它已经存在示例代码。这是uri。
https://github.com/googlesamples/android-ndk/tree/master/native-audio
我应该添加我的代码" loop-listener"在这个C代码(NDK)。
void Java_com_example_nativeaudio_NativeAudio_setPlayingAssetAudioPlayer(JNIEnv* env,
jclass clazz, jboolean isPlaying)
{
SLresult result;
// make sure the asset audio player was created
if (NULL != fdPlayerPlay) {
// set the player's state
result = (*fdPlayerPlay)->SetPlayState(fdPlayerPlay, isPlaying ?
SL_PLAYSTATE_PLAYING : SL_PLAYSTATE_PAUSED);
assert(SL_RESULT_SUCCESS == result);
(void)result;
//#todo set loop-listener function
}
}
有什么有用的功能或其他方式吗?请帮帮我!