|
|
|
@ -5,7 +5,6 @@ import android.app.Activity
|
|
|
|
|
import android.app.AlertDialog
|
|
|
|
|
import android.content.ContentValues
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.DialogInterface
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.content.pm.PackageManager
|
|
|
|
|
import android.net.Uri
|
|
|
|
@ -153,12 +152,17 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
private fun processVideoUri(inputVideoUri: Uri) {
|
|
|
|
|
// Save captured video for FFMPEG. Use MP4 extension, completely arbitrary.
|
|
|
|
|
val inputFile = File.createTempFile("input", ".mp4", cacheDir)
|
|
|
|
|
contentResolver.openInputStream(inputVideoUri).use { inputStream ->
|
|
|
|
|
if (inputStream == null)
|
|
|
|
|
return Unit .also { Log.e(TAG, "Could not open input file") }
|
|
|
|
|
FileOutputStream(inputFile).use { fos ->
|
|
|
|
|
fos.buffered().write(inputStream.buffered().readBytes())
|
|
|
|
|
try {
|
|
|
|
|
contentResolver.openInputStream(inputVideoUri).use { inputStream ->
|
|
|
|
|
if (inputStream == null)
|
|
|
|
|
return Unit.also { Log.e(TAG, "Could not open input file") }
|
|
|
|
|
FileOutputStream(inputFile).use { fos ->
|
|
|
|
|
fos.buffered().write(inputStream.buffered().readBytes())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (e: OutOfMemoryError) {
|
|
|
|
|
toast("Video is too large, Android broke!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
processVideo(inputFile.canonicalPath)
|
|
|
|
|
}
|
|
|
|
@ -179,14 +183,14 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
} ?: true
|
|
|
|
|
val duration = mediaInfo?.duration ?: 0
|
|
|
|
|
val duration = mediaInfo?.duration?.toLong() ?: 0L
|
|
|
|
|
|
|
|
|
|
// Save the soundtrack as well cause we can't pass a resource to FFMPEG.
|
|
|
|
|
// Should be done only once, then it's kept in app internal storage.
|
|
|
|
|
val themeId = getThemeRawResource(getThemeId())
|
|
|
|
|
val themeId = getThemeId()
|
|
|
|
|
val soundFile = File(filesDir, "$themeId.m4a")
|
|
|
|
|
if (!soundFile.exists()) {
|
|
|
|
|
resources.openRawResource(themeId).use { resource ->
|
|
|
|
|
resources.openRawResource(getThemeRawResource(themeId)).use { resource ->
|
|
|
|
|
FileOutputStream(soundFile).use { fos ->
|
|
|
|
|
fos.buffered().write(resource.buffered().readBytes())
|
|
|
|
|
}
|
|
|
|
@ -288,10 +292,11 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Suppress("DEPRECATION")
|
|
|
|
|
private fun save(): Boolean {
|
|
|
|
|
if (currentVideoPath == null)
|
|
|
|
|
return false
|
|
|
|
|
val currentFile = File(currentVideoPath)
|
|
|
|
|
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()
|
|
|
|
@ -358,6 +363,7 @@ class MainActivity : AppCompatActivity() {
|
|
|
|
|
when (id) {
|
|
|
|
|
0 -> R.raw.harvestdawn
|
|
|
|
|
1 -> R.raw.sunriseofflutes
|
|
|
|
|
2 -> R.raw.deathknell
|
|
|
|
|
else -> R.raw.harvestdawn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|