Note that there are some explanatory texts on larger screens.

plurals
  1. POProgressBar does not reset after audio is done
    primarykey
    data
    text
    <p>My ProgressBar does not reset after audio is done. It reset after some audio's but not others not sure why. Also would like to make pause icon change to play when audio is done if anyone can help out with that to, that will be great!</p> <p>Heres code:</p> <pre><code> public class player1 extends Activity implements Runnable { private MediaPlayer mp; private ProgressBar progressBar; private ImageButton pauseicon; private final int NUM_SOUND_FILES = 3; //*****REPLACE THIS WITH THE ACTUAL NUMBER OF SOUND FILES YOU HAVE***** private int mfile[] = new int[NUM_SOUND_FILES]; private Random rnd = new Random(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.player_1); pauseicon = (ImageButton) findViewById(R.id.pauseicon); progressBar = (ProgressBar) findViewById(R.id.progressBar); getActionBar().setDisplayHomeAsUpEnabled(true); mfile[0] = R.raw.sound01; //****REPLACE THESE WITH THE PROPER NAMES OF YOUR SOUND FILES mfile[1] = R.raw.sound02; //PLACE THE SOUND FILES IN THE /res/raw/ FOLDER IN YOUR PROJECT***** mfile[2] = R.raw.sound03; // Listeners /** * Play button click event * plays a song and changes button to pause image * pauses a song and changes button to play image * */ try{ mp = MediaPlayer.create(player1.this, mfile[rnd.nextInt(NUM_SOUND_FILES)]); mp.seekTo(0); mp.start(); ; progressBar.setVisibility(ProgressBar.VISIBLE); progressBar.setProgress(0); progressBar.setMax(mp.getDuration()); new Thread(this).start(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } pauseicon.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub if (v.getId() == R.id.pauseicon) if(mp.isPlaying()){ mp.pause(); ImageButton pauseicon =(ImageButton) findViewById(R.id.pauseicon); pauseicon.setImageResource(R.drawable.playicon); } else { mp.start(); ImageButton pauseicon =(ImageButton) findViewById(R.id.pauseicon); pauseicon.setImageResource(R.drawable.pauseicon); }}}); } public void run() { int currentPosition= 0; int total = mp.getDuration(); while (mp!=null &amp;&amp; currentPosition&lt;total) { try { Thread.sleep(1000); currentPosition= mp.getCurrentPosition(); } catch (InterruptedException e) { return; } catch (Exception e) { return; } progressBar.setProgress(currentPosition); } } public boolean onOptionsItemSelected(MenuItem item){ Intent myIntent = new Intent(getApplicationContext(), MainActivity.class); startActivityForResult(myIntent, 0); return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload