Pregunta

My sound file is 5 minute long. I want to play part of the sound file from minute 1:00 to 2:00. Any one has an idea:

mp = MediaPlayer.create(getApplicationContext(),soundID);  
mp.start();
¿Fue útil?

Solución

You should read about MediaPlayer, in particular about seekTo(int time).

seekTo receives time in milliseconds so for your case you should do as follows:

private static final int MILLISECONDS_IN_SECOND = 1000;
private static final int TIME_IN_SECONDS = 60;
...
mPlayer.seekTo(TIME_IN_SECONDS * MILLISECONDS_IN_SECOND);
mPlayer.start();

whereas mPlayer is your MediaPlayer.

Otros consejos

Please read the official Android documentation concerning MediaPlayer here.

seekTo(int pos) and getCurrentPosition() are the key methods used to solve your problem.

Maybe just cut the file to exactly what you need (using Audacity or something like that) it will also reduce app size if you're not using the rest of that file

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top