I'll make simple to understand then: What I want to have is that my two threads start at the same time and not that one waits for the other to finish what it has to do before starting. Here's the code:
public class MyClass extends Activity{
MediaPlayer player;
int timeToPause;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
final Runnable updateLyrics = new Runnable() {
@Override
public void run() {
while(player.isPlaying()){
if(inside(player.getCurrentPosition(), lyricsBegin[index], lyricsEnd[index])){
updateLyrics(lyrics[index]);
}
}
}
};
Runnable pausePlayer = new Runnable() {
@Override
public void run() {
while(player.isPlaying()){
if(player.getCurrentPosition()/1000 == timeToPause){
player.pause();
}
}
}
};
Thread threadUpdate = new Thread(updateLyrics);
Thread threadPause = new Thread(pausePlayer);
threadUpdate.start();
threadPause.start();
}
}
the function inside(int current, int begin, int end)
check if the current position of the player
is between the begin
and the end
, timeToPause
is the specific time where the player
should pause