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) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY) val store = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
else val videoDetails = ContentValues();
MediaStore.Video.Media.EXTERNAL_CONTENT_URI videoDetails.put(MediaStore.Video.Media.IS_PENDING, 1)
val videoDetails = ContentValues().apply { val uri = contentResolver.insert(store, videoDetails)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { ?: return false .also { toast("Could not put video to media store.") }
put(MediaStore.Video.Media.IS_PENDING, 1) contentResolver.openFileDescriptor(uri, "w").use { pfd ->
FileOutputStream(pfd?.fileDescriptor).use { fos ->
FileInputStream(currentVideoPath).use { fis ->
fos.buffered().write(fis.buffered().readBytes())
}
}
} }
} videoDetails.clear()
currentVideoUri = contentResolver.insert(videoStore, videoDetails) videoDetails.put(MediaStore.Video.Media.IS_PENDING, 0)
?: return false .also { toast("Could not save video to media store.") } contentResolver.update(uri, videoDetails, null, null)
contentResolver.openFileDescriptor(currentVideoUri!!, "w").use { pfd -> currentVideoUri = uri;
FileOutputStream(pfd?.fileDescriptor).use { fos -> toast("Video saved to media store!")
FileInputStream(currentVideoPath).use { fis -> } 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()) fos.buffered().write(fis.buffered().readBytes())
} }
} }
currentVideoUri = savedFile.toUri()
toast("Video saved to external storage!")
} }
videoDetails.apply {
clear()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
put(MediaStore.Video.Media.IS_PENDING, 0)
}
}
contentResolver.update(currentVideoUri!!, videoDetails, null, null)
toast("Video saved to media store!")
return true return true
} }