From 81ec8183e775a2dac75ebcdbcc9bda66d1bcd0ee Mon Sep 17 00:00:00 2001 From: Rohit Yengisetty Date: Wed, 18 Feb 2015 09:58:59 -0800 Subject: Gallery2 - Add support to pass in a playlist along with video to play Change-Id: I9d14dc8801f82f4e343917e094b05251f49d4152 (cherry picked from commit 6df83bf3723bbee27f5a7a9deaa218e2abedf607) --- .../codeaurora/gallery3d/ext/IMovieListLoader.java | 3 +- .../codeaurora/gallery3d/ext/MovieListLoader.java | 44 ++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/org/codeaurora/gallery3d/ext/IMovieListLoader.java b/src/org/codeaurora/gallery3d/ext/IMovieListLoader.java index db4c71347..fe5999858 100644 --- a/src/org/codeaurora/gallery3d/ext/IMovieListLoader.java +++ b/src/org/codeaurora/gallery3d/ext/IMovieListLoader.java @@ -1,5 +1,6 @@ package org.codeaurora.gallery3d.ext; +import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -35,7 +36,7 @@ public interface IMovieListLoader { * @param l * @param item */ - void fillVideoList(Context context, Intent intent, LoaderListener l, IMovieItem item); + void fillVideoList(Activity context, Intent intent, LoaderListener l, IMovieItem item); /** * enable video list or not. * @param intent diff --git a/src/org/codeaurora/gallery3d/ext/MovieListLoader.java b/src/org/codeaurora/gallery3d/ext/MovieListLoader.java index 840477ff6..94e6afd86 100644 --- a/src/org/codeaurora/gallery3d/ext/MovieListLoader.java +++ b/src/org/codeaurora/gallery3d/ext/MovieListLoader.java @@ -1,5 +1,6 @@ package org.codeaurora.gallery3d.ext; +import android.app.Activity; import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; @@ -12,6 +13,9 @@ import android.provider.MediaStore; import android.provider.OpenableColumns; import android.util.Log; +import java.io.File; +import java.util.ArrayList; + /** * Movie list loader class. It will load videos from MediaProvider database. * If MoviePlayer starting activity doesn't set any thing, default OrderBy will be used. @@ -24,7 +28,41 @@ public class MovieListLoader implements IMovieListLoader { private MovieListFetcherTask mListTask; @Override - public void fillVideoList(Context context, Intent intent, LoaderListener l, IMovieItem item) { + public void fillVideoList(Activity activity, Intent intent, final LoaderListener l, + IMovieItem currentMovieItem) { + + // determine if a video playlist has been passed in through the intent + // if a playlist does exist, use that + ArrayList uris = intent.getParcelableArrayListExtra("EXTRA_FILE_LIST"); + if (uris != null) { + final MovieList movieList = new MovieList(); + ContentResolver cr = activity.getContentResolver(); + + for(Uri uri : uris) { + // add currentMovieItem in its proper place in the video playlist + // 'Next' and 'Previous' functionality in MovieListHooker is dependent on reference + // matching currentMovieItem + if (currentMovieItem.getOriginalUri().equals(uri)) { + movieList.add(currentMovieItem); + continue; + } + + File videoFile = new File(uri.getPath()); + movieList.add(new MovieItem(uri, cr.getType(uri), videoFile.getName())); + } + + // notify callback on main thread + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + l.onListLoaded(movieList); + } + }); + + return; + } + + // proceed with creating a playlist if one isn't found boolean fetechAll = false; if (intent.hasExtra(EXTRA_ALL_VIDEO_FOLDER)) { fetechAll = intent.getBooleanExtra(EXTRA_ALL_VIDEO_FOLDER, false); @@ -35,8 +73,8 @@ public class MovieListLoader implements IMovieListLoader { orderBy = intent.getStringExtra(EXTRA_ORDERBY); } cancelList(); - mListTask = new MovieListFetcherTask(context, fetechAll, l, orderBy); - mListTask.execute(item); + mListTask = new MovieListFetcherTask(activity, fetechAll, l, orderBy); + mListTask.execute(currentMovieItem); if (LOG) { Log.v(TAG, "fillVideoList() fetechAll=" + fetechAll + ", orderBy=" + orderBy); } -- cgit v1.2.3