Added method to take screenshot of video call and save it into media store

This commit is contained in:
Sylvain Berfini 2021-01-11 12:12:57 +01:00
parent bb704a25b9
commit 908ef58162
2 changed files with 33 additions and 6 deletions

View file

@ -28,11 +28,14 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.compatibility.Compatibility
import org.linphone.contact.GenericContactViewModel
import org.linphone.core.Call
import org.linphone.core.CallListenerStub
import org.linphone.core.Factory
import org.linphone.core.tools.Log
import org.linphone.utils.Event
import org.linphone.utils.FileUtils
import org.linphone.utils.LinphoneUtils
class CallViewModelFactory(private val call: Call) :
@ -86,6 +89,23 @@ open class CallViewModel(val call: Call) : GenericContactViewModel(call.remoteAd
startTimer(call)
}
}
override fun onSnapshotTaken(call: Call, filePath: String) {
Log.i("[Call View Model] Snapshot taken, saved at $filePath")
val content = Factory.instance().createContent()
content.filePath = filePath
content.type = "image"
content.subtype = "jpeg"
content.name = filePath.substring(filePath.indexOf("/") + 1)
viewModelScope.launch {
if (Compatibility.addImageToMediaStore(coreContext.context, content)) {
Log.i("[Call View Model] Adding snapshot ${content.name} to Media Store terminated")
} else {
Log.e("[Call View Model] Something went wrong while copying file to Media Store...")
}
}
}
}
init {
@ -120,6 +140,13 @@ open class CallViewModel(val call: Call) : GenericContactViewModel(call.remoteAd
}
}
fun takeScreenshot() {
if (call.currentParams.videoEnabled()) {
val fileName = System.currentTimeMillis().toString() + ".jpeg"
call.takeVideoSnapshot(FileUtils.getFileStoragePath(fileName).absolutePath)
}
}
private fun startTimer(call: Call) {
timer?.cancel()

View file

@ -213,23 +213,23 @@ class ChatMessageViewModel(
when (content.type) {
"image" -> {
if (Compatibility.addImageToMediaStore(coreContext.context, content)) {
Log.i("[Chat Message] Adding image ${content.name} terminated")
Log.i("[Chat Message] Adding image ${content.name} to Media Store terminated")
} else {
Log.e("[Chat Message] Something went wrong while copying file...")
Log.e("[Chat Message] Something went wrong while copying file to Media Store...")
}
}
"video" -> {
if (Compatibility.addVideoToMediaStore(coreContext.context, content)) {
Log.i("[Chat Message] Adding video ${content.name} terminated")
Log.i("[Chat Message] Adding video ${content.name} to Media Store terminated")
} else {
Log.e("[Chat Message] Something went wrong while copying file...")
Log.e("[Chat Message] Something went wrong while copying file to Media Store...")
}
}
"audio" -> {
if (Compatibility.addAudioToMediaStore(coreContext.context, content)) {
Log.i("[Chat Message] Adding audio ${content.name} terminated")
Log.i("[Chat Message] Adding audio ${content.name} to Media Store terminated")
} else {
Log.e("[Chat Message] Something went wrong while copying file...")
Log.e("[Chat Message] Something went wrong while copying file to Media Store...")
}
}
else -> {