MainActivity: fix shit for jojo

This commit is contained in:
dece 2021-03-17 18:10:28 +01:00
parent 8b64425a45
commit 0e1128cf58

View file

@ -9,6 +9,7 @@ import android.net.Uri
import android.os.AsyncTask import android.os.AsyncTask
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore import android.provider.MediaStore
import android.util.Log import android.util.Log
import android.view.Menu import android.view.Menu
@ -20,6 +21,7 @@ import android.widget.Toast
import android.widget.VideoView import android.widget.VideoView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.core.net.toUri
import com.arthenica.mobileffmpeg.Config.RETURN_CODE_CANCEL import com.arthenica.mobileffmpeg.Config.RETURN_CODE_CANCEL
import com.arthenica.mobileffmpeg.Config.RETURN_CODE_SUCCESS import com.arthenica.mobileffmpeg.Config.RETURN_CODE_SUCCESS
import com.arthenica.mobileffmpeg.FFmpeg import com.arthenica.mobileffmpeg.FFmpeg
@ -252,33 +254,41 @@ class MainActivity : AppCompatActivity() {
private fun save(): Boolean { private fun save(): Boolean {
if (currentVideoPath == null) if (currentVideoPath == null)
return false return false
val videoStore = val currentFile = File(currentVideoPath)
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q)
MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
else
MediaStore.Video.Media.EXTERNAL_CONTENT_URI
val videoDetails = ContentValues().apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
put(MediaStore.Video.Media.IS_PENDING, 1) val store = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
} val videoDetails = ContentValues();
} videoDetails.put(MediaStore.Video.Media.IS_PENDING, 1)
currentVideoUri = contentResolver.insert(videoStore, videoDetails) val uri = contentResolver.insert(store, videoDetails)
?: return false .also { toast("Could not save video to media store.") } ?: return false .also { toast("Could not put video to media store.") }
contentResolver.openFileDescriptor(currentVideoUri!!, "w").use { pfd -> contentResolver.openFileDescriptor(uri, "w").use { pfd ->
FileOutputStream(pfd?.fileDescriptor).use { fos -> FileOutputStream(pfd?.fileDescriptor).use { fos ->
FileInputStream(currentVideoPath).use { fis -> FileInputStream(currentVideoPath).use { fis ->
fos.buffered().write(fis.buffered().readBytes()) fos.buffered().write(fis.buffered().readBytes())
} }
} }
} }
videoDetails.apply { videoDetails.clear()
clear() videoDetails.put(MediaStore.Video.Media.IS_PENDING, 0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { contentResolver.update(uri, videoDetails, null, null)
put(MediaStore.Video.Media.IS_PENDING, 0) currentVideoUri = uri;
}
}
contentResolver.update(currentVideoUri!!, videoDetails, null, null)
toast("Video saved to media store!") toast("Video saved to media store!")
} else {
val externalDir = File(
Environment.getExternalStorageDirectory(),
"Movies/HarvestDawn"
)
if (!externalDir.isDirectory)
externalDir.mkdirs()
val savedFile = File(externalDir, currentFile.name)
FileOutputStream(savedFile).use { fos ->
FileInputStream(currentFile).use { fis ->
fos.buffered().write(fis.buffered().readBytes())
}
}
currentVideoUri = savedFile.toUri()
toast("Video saved to external storage!")
}
return true return true
} }