-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #873 from UstadMobile/dev-compress
Dev compress
- Loading branch information
Showing
169 changed files
with
28,823 additions
and
809 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...Test/kotlin/com/ustadmobile/core/domain/compress/audio/CompressAudioUseCaseAndroidTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.ustadmobile.core.domain.compress.audio | ||
|
||
import android.content.Context | ||
import android.media.MediaCodecList | ||
import androidx.core.net.toUri | ||
import androidx.test.core.app.ApplicationProvider | ||
import com.ustadmobile.core.uri.UriHelperAndroid | ||
import com.ustadmobile.door.DoorUri | ||
import com.ustadmobile.door.ext.toFile | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Assert | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
|
||
class CompressAudioUseCaseAndroidTest { | ||
|
||
|
||
@JvmField | ||
@Rule | ||
var tempFolder = TemporaryFolder() | ||
|
||
@Test | ||
fun initTest() { | ||
val context = ApplicationProvider.getApplicationContext<Context>() | ||
|
||
val codecList = MediaCodecList(MediaCodecList.ALL_CODECS) | ||
val audioEncoders = codecList.codecInfos.filter { codecInfo -> | ||
codecInfo.isEncoder && codecInfo.supportedTypes.any { it.startsWith("audio") } | ||
} | ||
println(audioEncoders.flatMap { it.supportedTypes.toList() }.joinToString()) | ||
|
||
val compressAudioUseCase = CompressAudioUseCaseAndroid( | ||
appContext = context, | ||
uriHelper = UriHelperAndroid(context) | ||
) | ||
val audioFile = tempFolder.newFile() | ||
this::class.java.getResourceAsStream("/river.mp3")!!.use { inStream -> | ||
audioFile.outputStream().use { | ||
inStream.copyTo(it) | ||
it.flush() | ||
} | ||
} | ||
|
||
val result = runBlocking { | ||
compressAudioUseCase( | ||
fromUri = audioFile.toUri().toString(), | ||
) | ||
} | ||
|
||
Assert.assertNotNull(result) | ||
|
||
val resultFile = DoorUri.parse(result!!.uri).toFile() | ||
assertTrue(resultFile.exists()) | ||
assertTrue(resultFile.length() > 0) | ||
println("result for is ${resultFile.length()}") | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...Test/kotlin/com/ustadmobile/core/domain/compress/video/CompressVideoUseCaseAndroidTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.ustadmobile.core.domain.compress.video | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import androidx.core.net.toFile | ||
import androidx.core.net.toUri | ||
import androidx.test.core.app.ApplicationProvider | ||
import com.ustadmobile.core.domain.compress.CompressParams | ||
import com.ustadmobile.core.domain.compress.CompressionLevel | ||
import com.ustadmobile.core.uri.UriHelperAndroid | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Assert | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
|
||
class CompressVideoUseCaseAndroidTest { | ||
|
||
@JvmField | ||
@Rule | ||
var tempFolder = TemporaryFolder() | ||
|
||
lateinit var videoFile: File | ||
|
||
lateinit var useCase: CompressVideoUseCaseAndroid | ||
|
||
@Before | ||
fun setup() { | ||
val context = ApplicationProvider.getApplicationContext<Context>() | ||
val uriHelper = UriHelperAndroid(context) | ||
useCase = CompressVideoUseCaseAndroid(context, uriHelper) | ||
|
||
videoFile = tempFolder.newFile("bus.mp4") | ||
this::class.java.getResourceAsStream("/bus.mp4")!!.use { assetIn -> | ||
FileOutputStream(videoFile).use { fileOut -> | ||
assetIn.copyTo(fileOut) | ||
fileOut.flush() | ||
} | ||
} | ||
} | ||
|
||
private fun compressAndAssert(compressionLevel: CompressionLevel) { | ||
runBlocking { | ||
val result = useCase( | ||
fromUri = videoFile.toUri().toString(), | ||
params = CompressParams( | ||
compressionLevel = compressionLevel | ||
) | ||
) | ||
|
||
val outFile = Uri.parse(result!!.uri).toFile() | ||
Assert.assertTrue(outFile.length() > 0) | ||
} | ||
} | ||
|
||
@Test | ||
fun givenValidVideo_whenCompressLow_thenWillCompress() { | ||
compressAndAssert(CompressionLevel.LOW) | ||
} | ||
|
||
@Test | ||
fun givenValidVideo_whenCompressMedium_thenWillCompress() { | ||
compressAndAssert(CompressionLevel.MEDIUM) | ||
} | ||
|
||
@Test | ||
fun givenValidVideo_whenCompressHigh_thenWillCompress() { | ||
compressAndAssert(CompressionLevel.HIGH) | ||
} | ||
|
||
|
||
} |
Binary file not shown.
Binary file not shown.
File renamed without changes
Binary file not shown.
Oops, something went wrong.