how to display the duration of my song? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



how to display the duration of my song? [duplicate]



This question already has an answer here:



I would like to display the duration of the song.


public class Songs extends AppCompatActivity
MediaPlayer song;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_surah);
song=MediaPlayer.create(Songs.this,R.raw.song);

public void play1(View v)
song.start();

public void pause1(View v)
song.pause();




This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





this answer may be useful [ stackoverflow.com/a/20543679/5919568 ]
– Morteza Jalambadani
Aug 12 at 4:36




1 Answer
1



You can use Timer which will be updated every 1000 milliseconds. Then set time to a TextView or what ever you want.


Timer


TextView


song.start();
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask()
@Override
public void run()
runOnUiThread(new Runnable()
@Override
public void run()
if (song != null && song.isPlaying())
tv.post(new Runnable()
@Override
public void run()
tv.setText(song.getCurrentPosition());

);
else
timer.cancel();
timer.purge();


);

, 0, 1000);

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS