From 86249162bb50fce32113416e47e9985461dd67d7 Mon Sep 17 00:00:00 2001 From: Jonathan Trowbridge Date: Wed, 11 Jul 2018 15:03:23 -0400 Subject: [PATCH] master - Updated sample to support pre KitKat devices. --- sample/build.gradle | 3 +++ sample/src/main/AndroidManifest.xml | 22 ++++++++++++++++ .../activities/MainActivity.java | 26 ++++++++++++++----- sample/src/main/res/values/styles.xml | 23 ++++++++++++++++ 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/sample/build.gradle b/sample/build.gradle index 2798978..98ad40e 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -37,6 +37,9 @@ dependencies { implementation 'com.android.support.constraint:constraint-layout:1.1.2' implementation 'com.android.support:design:27.1.1' + // Provides file picker for pre KitKat (API 19) devices. + implementation 'com.nononsenseapps:filepicker:4.1.0' + implementation project(path: ':simplevlcplayer') } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index e7fa0d1..c1c50e7 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -25,6 +25,28 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/src/main/java/com/masterwok/demosimplevlcplayer/activities/MainActivity.java b/sample/src/main/java/com/masterwok/demosimplevlcplayer/activities/MainActivity.java index 7833fcd..97e4bc3 100644 --- a/sample/src/main/java/com/masterwok/demosimplevlcplayer/activities/MainActivity.java +++ b/sample/src/main/java/com/masterwok/demosimplevlcplayer/activities/MainActivity.java @@ -3,13 +3,16 @@ import android.app.Activity; import android.content.Intent; import android.net.Uri; +import android.os.Build; import android.os.Bundle; +import android.os.Environment; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.AppCompatButton; import com.masterwok.demosimplevlcplayer.R; import com.masterwok.simplevlcplayer.VlcOptionsProvider; import com.masterwok.simplevlcplayer.activities.MediaPlayerActivity; +import com.nononsenseapps.filepicker.FilePickerActivity; /** @@ -74,8 +77,20 @@ protected void onStart() { * Show the activity for picking file. */ private void showOpenDocumentActivity() { - Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); - intent.setType("*/*"); + Intent intent; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + // Use storage access framework + intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.setType("*/*"); + } else { + // Fallback to external file picker. + intent = new Intent(this, FilePickerActivity.class); + intent.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); + intent.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false); + intent.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE); + intent.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath()); + } startActivityForResult(intent, OpenDocumentRequestCode); } @@ -106,15 +121,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { private void startMediaPlayerActivity(Uri videoUri, Uri subtitleUri) { Intent intent = new Intent(this, MediaPlayerActivity.class); - intent.putExtra(MediaPlayerActivity.MediaUri, videoUri); - intent.putExtra(MediaPlayerActivity.SubtitleUri, subtitleUri); - + // Example of using an http resource. // intent.putExtra(MediaPlayerActivity.MediaUri, Uri.parse( // "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4" //// "http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_1080p_stereo.avi" // )); - // TODO: Seek partial files setTime fails when seeking past downloaded portion of file. + intent.putExtra(MediaPlayerActivity.MediaUri, videoUri); + intent.putExtra(MediaPlayerActivity.SubtitleUri, subtitleUri); startActivity(intent); } diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml index 177cefc..54d554a 100644 --- a/sample/src/main/res/values/styles.xml +++ b/sample/src/main/res/values/styles.xml @@ -17,4 +17,27 @@ + + +