From 119276672ae1cf2c58b3d2f6734e0ea52c003a64 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 25 Feb 2018 13:43:25 +0100 Subject: [PATCH] properly play videos if their filename contains a colon --- app/build.gradle | 2 +- .../simplemobiletools/gallery/fragments/VideoFragment.kt | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7179a8da5..3898d3175 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.13.6' + implementation 'com.simplemobiletools:commons:3.13.7' implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0' implementation 'com.android.support:multidex:1.0.2' implementation 'com.google.code.gson:gson:2.8.2' 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 ff6d46b89..ce03f165b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -14,6 +14,7 @@ import android.view.animation.AnimationUtils import android.widget.SeekBar import android.widget.TextView import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.VideoActivity import com.simplemobiletools.gallery.extensions.* @@ -21,6 +22,7 @@ import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.helpers.MediaSideScroll import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.pager_video_item.view.* +import java.io.File import java.io.IOException class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSeekBarChangeListener { @@ -315,9 +317,12 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee } val mediumPath = if (wasEncoded) mEncodedPath else getPathToLoad(medium) + + // this workaround is needed for example if the filename contains a colon + val fileUri = if (mediumPath.startsWith("/")) context!!.getFilePublicUri(File(mediumPath), BuildConfig.APPLICATION_ID) else Uri.parse(mediumPath) try { mMediaPlayer = MediaPlayer().apply { - setDataSource(context, Uri.parse(mediumPath)) + setDataSource(context, fileUri) setDisplay(mSurfaceHolder) setOnCompletionListener { videoCompleted() } setOnVideoSizeChangedListener { mediaPlayer, width, height -> setVideoSize() }