MainActivity: fix shit for jojo
This commit is contained in:
parent
8b64425a45
commit
0e1128cf58
|
@ -9,6 +9,7 @@ import android.net.Uri
|
|||
import android.os.AsyncTask
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.provider.MediaStore
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
|
@ -20,6 +21,7 @@ import android.widget.Toast
|
|||
import android.widget.VideoView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
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_SUCCESS
|
||||
import com.arthenica.mobileffmpeg.FFmpeg
|
||||
|
@ -252,33 +254,41 @@ class MainActivity : AppCompatActivity() {
|
|||
private fun save(): Boolean {
|
||||
if (currentVideoPath == null)
|
||||
return false
|
||||
val videoStore =
|
||||
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) {
|
||||
put(MediaStore.Video.Media.IS_PENDING, 1)
|
||||
val currentFile = File(currentVideoPath)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val store = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
||||
val videoDetails = ContentValues();
|
||||
videoDetails.put(MediaStore.Video.Media.IS_PENDING, 1)
|
||||
val uri = contentResolver.insert(store, videoDetails)
|
||||
?: return false .also { toast("Could not put video to media store.") }
|
||||
contentResolver.openFileDescriptor(uri, "w").use { pfd ->
|
||||
FileOutputStream(pfd?.fileDescriptor).use { fos ->
|
||||
FileInputStream(currentVideoPath).use { fis ->
|
||||
fos.buffered().write(fis.buffered().readBytes())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
currentVideoUri = contentResolver.insert(videoStore, videoDetails)
|
||||
?: return false .also { toast("Could not save video to media store.") }
|
||||
contentResolver.openFileDescriptor(currentVideoUri!!, "w").use { pfd ->
|
||||
FileOutputStream(pfd?.fileDescriptor).use { fos ->
|
||||
FileInputStream(currentVideoPath).use { fis ->
|
||||
videoDetails.clear()
|
||||
videoDetails.put(MediaStore.Video.Media.IS_PENDING, 0)
|
||||
contentResolver.update(uri, videoDetails, null, null)
|
||||
currentVideoUri = uri;
|
||||
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!")
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue