properly play OTG videos

This commit is contained in:
tibbi 2018-02-20 16:12:43 +01:00
parent 66993d784e
commit c25513fbcf
3 changed files with 9 additions and 10 deletions

View file

@ -24,7 +24,6 @@ import com.bumptech.glide.request.target.Target
import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.PhotoActivity import com.simplemobiletools.gallery.activities.PhotoActivity
import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.activities.ViewPagerActivity
@ -205,7 +204,7 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadGif() { private fun loadGif() {
try { try {
val pathToLoad = getPathToLoad() val pathToLoad = getPathToLoad(medium)
gifDrawable = if (pathToLoad.startsWith("content://") || pathToLoad.startsWith("file://")) { gifDrawable = if (pathToLoad.startsWith("content://") || pathToLoad.startsWith("file://")) {
GifDrawable(context!!.contentResolver, Uri.parse(pathToLoad)) GifDrawable(context!!.contentResolver, Uri.parse(pathToLoad))
} else { } else {
@ -243,7 +242,7 @@ class PhotoFragment : ViewPagerFragment() {
Glide.with(this) Glide.with(this)
.asBitmap() .asBitmap()
.load(getPathToLoad()) .load(getPathToLoad(medium))
.apply(options) .apply(options)
.listener(object : RequestListener<Bitmap> { .listener(object : RequestListener<Bitmap> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean) = false override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean) = false
@ -261,7 +260,7 @@ class PhotoFragment : ViewPagerFragment() {
Glide.with(this) Glide.with(this)
.asBitmap() .asBitmap()
.load(getPathToLoad()) .load(getPathToLoad(medium))
.thumbnail(0.2f) .thumbnail(0.2f)
.apply(options) .apply(options)
.into(view.gif_view) .into(view.gif_view)
@ -275,7 +274,7 @@ class PhotoFragment : ViewPagerFragment() {
maxScale = 10f maxScale = 10f
beVisible() beVisible()
isQuickScaleEnabled = context.config.oneFingerZoom isQuickScaleEnabled = context.config.oneFingerZoom
setImage(ImageSource.uri(getPathToLoad())) setImage(ImageSource.uri(getPathToLoad(medium)))
orientation = if (imageOrientation == -1) SubsamplingScaleImageView.ORIENTATION_USE_EXIF else degreesForRotation(imageOrientation) orientation = if (imageOrientation == -1) SubsamplingScaleImageView.ORIENTATION_USE_EXIF else degreesForRotation(imageOrientation)
setEagerLoadingEnabled(false) setEagerLoadingEnabled(false)
setExecutor(AsyncTask.SERIAL_EXECUTOR) 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 { private fun getImageOrientation(): Int {
val defaultOrientation = -1 val defaultOrientation = -1
var orient = defaultOrientation var orient = defaultOrientation

View file

@ -183,7 +183,6 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
private fun initTimeHolder() { private fun initTimeHolder() {
val res = resources val res = resources
val height = context!!.navigationBarHeight
val left = mTimeHolder!!.paddingLeft val left = mTimeHolder!!.paddingLeft
val top = mTimeHolder!!.paddingTop val top = mTimeHolder!!.paddingTop
var right = mTimeHolder!!.paddingRight var right = mTimeHolder!!.paddingRight
@ -315,7 +314,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
return return
} }
val mediumPath = if (wasEncoded) mEncodedPath else medium.path val mediumPath = if (wasEncoded) mEncodedPath else getPathToLoad(medium)
try { try {
mMediaPlayer = MediaPlayer().apply { mMediaPlayer = MediaPlayer().apply {
setDataSource(context, Uri.parse(mediumPath)) setDataSource(context, Uri.parse(mediumPath))
@ -327,7 +326,7 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
prepare() prepare()
} }
} catch (e: IOException) { } catch (e: IOException) {
mEncodedPath = Uri.encode(medium.path) mEncodedPath = Uri.encode(getPathToLoad(medium))
if (wasEncoded) { if (wasEncoded) {
releaseMediaPlayer() releaseMediaPlayer()
} else { } else {

View file

@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.fragments
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.helpers.*
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
@ -65,4 +66,6 @@ abstract class ViewPagerFragment : Fragment() {
} }
return details.toString().trim() return details.toString().trim()
} }
fun getPathToLoad(medium: Medium) = if (medium.path.startsWith(OTG_PATH)) medium.path.getOTGPublicPath(context!!) else medium.path
} }