我怎样才能获得完成的重复值mp.setLooping(true)
。我可以OnCompletionListener
用来获取重复次数,但它会在循环之间产生 1 秒的延迟,这在面向音乐的应用程序中很烦人。OnCompletionListener
循环不像mp.setLooping(true)
.
有什么建议么 ?预先感谢。
循环之间有 1 秒延迟或间隙的代码:
public class MainActivity extends Activity {
MediaPlayer mp1;
Button play;
int maxCount=10,n=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
play = (Button) findViewById(R.id.button1);
mp = MediaPlayer.create(MainActivity.this, R.raw.soundfile);
play.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mpplay();
}
});
}
private void mpplay() {
mp1.start();
mp1.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp1) {
if (n <= maxCount) {
mp1.start();
n++;
if (n >= maxCount) {
n = 1;
mp1.stop();
}
}
}
});
}}