Note that there are some explanatory texts on larger screens.

plurals
  1. POApp hangs while calculating the duration of media file
    primarykey
    data
    text
    <p>I am trying to calculate the duration of a media file and updating the list upon retrieval. I am using <code>asyncTask</code> for calculating the duration. But app hangs for the duration till it is calculating the size. Why is it happening? Is there a better approach?</p> <p>My async task is:- ew <code>LongOperation().execute(mFileMang.getCurrentDir()+"/" + mDataSource.get(position));</code></p> <pre><code> private class LongOperation extends AsyncTask&lt;String, Void, String&gt; { @Override protected String doInBackground(String... params) { MediaPlayer mp = MediaPlayer.create(mContext, Uri.parse(params[0])); long duration = mp.getDuration(); mp.reset(); mp.release(); String finalTimerString = ""; String secondsString = ""; String minutesString = ""; // Convert total duration into time int hours = (int)( duration / (1000*60*60)); int minutes = (int)(duration % (1000*60*60)) / (1000*60); int seconds = (int) ((duration % (1000*60*60)) % (1000*60) / 1000); // Add hours if there if(hours &gt; 0){ finalTimerString = hours + ":"; } // Prepending 0 to seconds if it is one digit if(seconds &lt; 10){ secondsString = "0" + seconds; }else{ secondsString = "" + seconds;} if(minutes &lt; 10){ minutesString = "0" + minutes; }else{ minutesString = "" + minutes;} duration_video = finalTimerString = finalTimerString + minutesString + ":" + secondsString; return null; } @Override protected void onPostExecute(String result) { //might want to change "executed" for the returned string passed into onPostExecute() but that is upto you } @Override protected void onPreExecute() { } @Override protected void onProgressUpdate(Void... values) { } </code></pre> <p>}</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.
 

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