Small fixes for the video transcoding playground app.
This commit is contained in:
parent
0f7f866562
commit
69d62d385e
3 changed files with 19 additions and 10 deletions
|
@ -99,8 +99,8 @@ class TranscodeTestRepository(context: Context) {
|
|||
workManager.pruneWork()
|
||||
}
|
||||
|
||||
fun cleanFailedTranscodes(context: Context) {
|
||||
context.filesDir.listFiles()?.filter { it.name.endsWith(TranscodeWorker.TEMP_FILE_EXTENSION) }?.forEach {
|
||||
fun cleanPrivateStorage(context: Context) {
|
||||
context.filesDir.listFiles()?.forEach {
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ class TranscodeTestViewModel : ViewModel() {
|
|||
|
||||
fun setOutputDirectoryAndCleanFailedTranscodes(context: Context, folderUri: Uri) {
|
||||
outputDirectory = folderUri
|
||||
repository.cleanFailedTranscodes(context)
|
||||
repository.cleanPrivateStorage(context)
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
|
|
|
@ -51,7 +51,7 @@ class TranscodeWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker(
|
|||
}
|
||||
|
||||
val inputParams = InputParams(inputData)
|
||||
val inputFilename = DocumentFile.fromSingleUri(applicationContext, inputParams.inputUri)?.name
|
||||
val inputFilename = DocumentFile.fromSingleUri(applicationContext, inputParams.inputUri)?.name?.removeFileExtension()
|
||||
if (inputFilename == null) {
|
||||
Log.w(TAG, "$logPrefix Could not read input file name!")
|
||||
return Result.failure()
|
||||
|
@ -151,13 +151,13 @@ class TranscodeWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker(
|
|||
return Result.failure()
|
||||
}
|
||||
|
||||
val tempFile = File(applicationContext.filesDir, tempFilename)
|
||||
if (!tempFile.delete()) {
|
||||
Log.w(TAG, "$logPrefix Failed to delete temp file after processing!")
|
||||
return Result.failure()
|
||||
}
|
||||
Log.v(TAG, "$logPrefix Faststart postprocess successful.")
|
||||
}
|
||||
val tempFile = File(applicationContext.filesDir, tempFilename)
|
||||
if (!tempFile.delete()) {
|
||||
Log.w(TAG, "$logPrefix Failed to delete temp file after processing!")
|
||||
return Result.failure()
|
||||
}
|
||||
Log.v(TAG, "$logPrefix Faststart postprocess successful.")
|
||||
}
|
||||
Log.v(TAG, "$logPrefix Overall transcode job successful.")
|
||||
return Result.success()
|
||||
|
@ -199,6 +199,15 @@ class TranscodeWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker(
|
|||
return DocumentFile.fromTreeUri(applicationContext, treeUri)?.createFile(VideoConstants.VIDEO_MIME_TYPE, filename)
|
||||
}
|
||||
|
||||
private fun String.removeFileExtension(): String {
|
||||
val lastDot = this.lastIndexOf('.')
|
||||
return if (lastDot != -1) {
|
||||
this.substring(0, lastDot)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
private class WorkerMediaDataSource(private val file: File) : InputStreamMediaDataSource() {
|
||||
|
||||
private val size = file.length()
|
||||
|
|
Loading…
Add table
Reference in a new issue