Last active
August 21, 2017 21:19
-
-
Save benbaxter/69cf49f369e6ff46c53bcf6d1ea31bf0 to your computer and use it in GitHub Desktop.
Loads a bitmap from an async task.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void getThumbnail(int index, ResultCallback callback) { | |
LoadBitmapAsyncTask task = new LoadBitmapAsyncTask(index, callback); | |
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | |
} | |
class LoadBitmapAsyncTask extends AsyncTask<Void, Void, Bitmap> { | |
final int mIndex; | |
final ResultCallback mResultCallback; | |
public LoadBitmapAsyncTask(int index, ResultCallback resultCallback) { | |
mIndex = index; | |
mResultCallback = resultCallback; | |
} | |
@Override | |
protected Bitmap doInBackground(Void... voids) { | |
MediaMetadataRetriever retriever = new MediaMetadataRetriever(); | |
retriever.setDataSource(mVideoUrl, new HashMap<>()); | |
long position = getSeekPositions()[index]; | |
Log.d("SeekProvider", "position: " + position); | |
Bitmap thumbnail = retriever.getFrameAtTime(position, | |
MediaMetadataRetriever.OPTION_CLOSEST); | |
retriever.release(); | |
return thumbnail; | |
} | |
@Override | |
protected void onPostExecute(Bitmap bitmap) { | |
super.onPostExecute(bitmap); | |
mResultCallback.onThumbnailLoaded(bitmap, mIndex); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment