Am just trying to play music via Media Player for n secs.
My First File:
public void Play_Music() {
mTestUtils.ConnectDevice();
mTestUtils.playMusic(MUSIC_PATH, STREAM_TIME);
mTestUtils.DisconnectDevice(();
}
My Second File:
public void playMusic(String music_path, int stream_time) {
MediaPlayer mMediaPlayer = new MediaPlayer();
try {
Log.i(TAG, "In Play mUsic");
mMediaPlayer.setDataSource(music_path);
mMediaPlayer.prepare();
mMediaPlayer.start();
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
Log.i(TAG, "In Handler");
mMediaPlayer.stop();
mMediaPlayer.release();
}
}, stream_time);
Log.i(TAG, "Done Playing");
} catch (IOException e) {
e.printStackTrace();
}
return;
}
Here my problem is how to make handler wait for given time. What is happening here is play music gets called, it executes that function and come back immediately to execute next statement in first file. I want to wait until handler function gets completed and after that i need to pass the control to first file.
Thanks in advance.