From c25513fbcf425cdc5143e5be7ab9eea539652683 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 20 Feb 2018 16:12:43 +0100 Subject: [PATCH] properly play OTG videos --- .../gallery/fragments/PhotoFragment.kt | 11 ++++------- .../gallery/fragments/VideoFragment.kt | 5 ++--- .../gallery/fragments/ViewPagerFragment.kt | 3 +++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index fba95f9f5..d53a36a04 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -24,7 +24,6 @@ import com.bumptech.glide.request.target.Target import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.PhotoActivity import com.simplemobiletools.gallery.activities.ViewPagerActivity @@ -205,7 +204,7 @@ class PhotoFragment : ViewPagerFragment() { private fun loadGif() { try { - val pathToLoad = getPathToLoad() + val pathToLoad = getPathToLoad(medium) gifDrawable = if (pathToLoad.startsWith("content://") || pathToLoad.startsWith("file://")) { GifDrawable(context!!.contentResolver, Uri.parse(pathToLoad)) } else { @@ -243,7 +242,7 @@ class PhotoFragment : ViewPagerFragment() { Glide.with(this) .asBitmap() - .load(getPathToLoad()) + .load(getPathToLoad(medium)) .apply(options) .listener(object : RequestListener { override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean) = false @@ -261,7 +260,7 @@ class PhotoFragment : ViewPagerFragment() { Glide.with(this) .asBitmap() - .load(getPathToLoad()) + .load(getPathToLoad(medium)) .thumbnail(0.2f) .apply(options) .into(view.gif_view) @@ -275,7 +274,7 @@ class PhotoFragment : ViewPagerFragment() { maxScale = 10f beVisible() isQuickScaleEnabled = context.config.oneFingerZoom - setImage(ImageSource.uri(getPathToLoad())) + setImage(ImageSource.uri(getPathToLoad(medium))) orientation = if (imageOrientation == -1) SubsamplingScaleImageView.ORIENTATION_USE_EXIF else degreesForRotation(imageOrientation) setEagerLoadingEnabled(false) setExecutor(AsyncTask.SERIAL_EXECUTOR) @@ -310,8 +309,6 @@ class PhotoFragment : ViewPagerFragment() { } } - private fun getPathToLoad() = if (medium.path.startsWith(OTG_PATH)) medium.path.getOTGPublicPath(context!!) else medium.path - private fun getImageOrientation(): Int { val defaultOrientation = -1 var orient = defaultOrientation diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index 1f7ee9084..ff6d46b89 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -183,7 +183,6 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee private fun initTimeHolder() { val res = resources - val height = context!!.navigationBarHeight val left = mTimeHolder!!.paddingLeft val top = mTimeHolder!!.paddingTop var right = mTimeHolder!!.paddingRight @@ -315,7 +314,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee return } - val mediumPath = if (wasEncoded) mEncodedPath else medium.path + val mediumPath = if (wasEncoded) mEncodedPath else getPathToLoad(medium) try { mMediaPlayer = MediaPlayer().apply { setDataSource(context, Uri.parse(mediumPath)) @@ -327,7 +326,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee prepare() } } catch (e: IOException) { - mEncodedPath = Uri.encode(medium.path) + mEncodedPath = Uri.encode(getPathToLoad(medium)) if (wasEncoded) { releaseMediaPlayer() } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt index fecbcc23d..d1c9a4253 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/ViewPagerFragment.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.fragments import android.support.v4.app.Fragment import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Medium @@ -65,4 +66,6 @@ abstract class ViewPagerFragment : Fragment() { } return details.toString().trim() } + + fun getPathToLoad(medium: Medium) = if (medium.path.startsWith(OTG_PATH)) medium.path.getOTGPublicPath(context!!) else medium.path }