Wednesday, April 17, 2013

[android help] How to set Media player Duration in android

How to set Media player Duration in android - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















i want to play MediaPlayer for 1 second. How to set Duration in this code..



player = MediaPlayer.create(getApplicationContext(), R.raw.beepsound);
player.start();

CountDownTimer Timer = new CountDownTimer(1000, 1000) {

@Override
public void onTick(long millisUntilFinished) {

player.start();
}

@Override
public void onFinish() {
// TODO Auto-generated method stub

player.stop();
}
};
Timer.start();




























You don't need to do anything on the onTick method.


Try this code:



player = MediaPlayer.create(getApplicationContext(), R.raw.beepsound);
player.start();

CountDownTimer timer = new CountDownTimer(1000, 1000) {

@Override
public void onTick(long millisUntilFinished) {
// Nothing to do
}

@Override
public void onFinish() {
if (player.isPlaying())
player.stop();
}
};
timer.start();






















You could use TimerTask to schedule a MediaPlayer.stop() to run after 1 secs.



TimerTask doAsynchronousTask = new TimerTask() {
@Override
public void run() {
MediaPlayer.stop()
}
};
timer.schedule(doAsynchronousTask, 0, "Set Time what you want"); //execute in every 20000 ms
}



















default






.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...