Note that there are some explanatory texts on larger screens.

plurals
  1. POAudio seekBar Thread Problem?
    primarykey
    data
    text
    <p>Originally, I had a MediaPlayer mPlayers to play/pause/stop my Audio file. Now, I'm trying to add a seek bar for my media. I tried using Threads and this is what I came up with:</p> <p>In onCreate() :</p> <pre><code>seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub mPlayer.seekTo(progress); } ////........Omitted Code..........\\\\ //At the very end of the method: seekThread = new Thread(this); //My Activity implements:Runnable seekThread.start(); </code></pre> <p>Then, I implemented a method <code>run()</code> to update my seek bar every 1 sec:</p> <pre><code>public void run() { try { while(mPlayer != null){ int currentPosition = mPlayer.getCurrentPosition(); Message msg = new Message(); msg.what = currentPosition; threadHandler.sendMessage(msg); Thread.sleep(1000); } } catch (InterruptedException e) { e.printStackTrace(); } } private Handler threadHandler = new Handler(){ public void handleMessage(Message msg){ seekBar.setProgress(msg.what); } }; </code></pre> <p>However, In my <em>HTC Magic</em>, the audio run inefficiently. Some words are repeated. It seems like the seek bar is going back a little bit every some time.</p> <p>To make you understand the problem well, Let's say this: if the audio says that: abcdefghijklmn , then it will be like this: abccdeffghijjklmnn.</p> <p><strong>Any improvement you suggest to my thread ? Am I doing it right?</strong></p>
    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.
 

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