我试图为此创建一个媒体播放器应用程序,我创建了一个自定义类及其构造函数,并且我在这里也使用了线程概念。但我不能MediaPlayer.create()
在这个方法中使用我该怎么做,请有人帮我解决这个问题......
代码
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
public class CustomPlayerActivity implements Runnable{
int song_id;
long time;
int button_id;
MediaPlayer myStereo;
public CustomPlayerActivity(int s_id, long Time, int b_id){
song_id = s_id;
time = Time;
button_id = b_id;
}
public void run(){
long start = System.currentTimeMillis();
long end = start + time;
while (System.currentTimeMillis() < end){
myStereo = MediaPlayer.create(this, R.raw.chuva);
myStereo.setLooping(true);
myStereo.start();
myStereo.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
myStereo.setLooping(true);
myStereo.start();
}
});
}
}
}