Compare commits

...

2 Commits

Author SHA1 Message Date
dece 878fa763c4 gradle: bump to 1.3
3 years ago
dece 0e2d4a8f12 MainActivity: prevent crash on file too big
3 years ago

@ -9,8 +9,8 @@ android {
applicationId "io.lowrespalmtree.harvestdawn"
minSdkVersion 24
targetSdkVersion 29
versionCode 3
versionName "1.2"
versionCode 4
versionName "1.3"
}
buildTypes {

@ -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
}

@ -3,5 +3,6 @@
<string-array name="pick_theme">
<item>@string/theme_harvestdawn</item>
<item>@string/theme_sunriseofflutes</item>
<item>@string/theme_deathknell</item>
</string-array>
</resources>

@ -10,4 +10,5 @@
<string name="action_theme">Theme</string>
<string name="theme_harvestdawn">Harvest Dawn</string>
<string name="theme_sunriseofflutes">Sunrise of Flutes</string>
<string name="theme_deathknell">Death Knell</string>
</resources>
Loading…
Cancel
Save