Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The Music sample app has a class <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/2.1_r2/com/android/music/MusicUtils.java" rel="nofollow">MusicUtils</a>:</p> <pre><code> /* Try to use String.format() as little as possible, because it creates a * new Formatter every time you call it, which is very inefficient. * Reusing an existing Formatter more than tripled the speed of * makeTimeString(). * This Formatter/StringBuilder are also used by makeAlbumSongsLabel() */ private static StringBuilder sFormatBuilder = new StringBuilder(); private static Formatter sFormatter = new Formatter(sFormatBuilder, Locale.getDefault()); private static final Object[] sTimeArgs = new Object[5]; public static String makeTimeString(Context context, long secs) { String durationformat = context.getString( secs &lt; 3600 ? R.string.durationformatshort : R.string.durationformatlong); /* Provide multiple arguments so the format can be changed easily * by modifying the xml. */ sFormatBuilder.setLength(0); final Object[] timeArgs = sTimeArgs; timeArgs[0] = secs / 3600; timeArgs[1] = secs / 60; timeArgs[2] = (secs / 60) % 60; timeArgs[3] = secs; timeArgs[4] = secs % 60; return sFormatter.format(durationformat, timeArgs).toString(); } </code></pre> <p>which you can use.</p> <p>But carlovv's solution will work too, if you divide the result of getCurrentPosition() by 1000, as the method returns milliseconds.</p> <p>this is what goes in your strings.xml</p> <pre><code> &lt;string translatable="false" name="durationformatshort"&gt; &lt;xliff:g id="format"&gt;%2$d:%5$02d&lt;/xliff:g&gt; &lt;/string&gt; &lt;string translatable="false" name="durationformatlong"&gt; &lt;xliff:g id="format"&gt;%1$d:%3$02d:%5$02d&lt;/xliff:g&gt; &lt;/string&gt; </code></pre>
 

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