From 908ef5816295b19e35903a74704ce9766bf5efab Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 11 Jan 2021 12:12:57 +0100 Subject: [PATCH] Added method to take screenshot of video call and save it into media store --- .../call/viewmodels/CallViewModel.kt | 27 +++++++++++++++++++ .../chat/viewmodels/ChatMessageViewModel.kt | 12 ++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/linphone/activities/call/viewmodels/CallViewModel.kt b/app/src/main/java/org/linphone/activities/call/viewmodels/CallViewModel.kt index 27f0043a7..2dbac2375 100644 --- a/app/src/main/java/org/linphone/activities/call/viewmodels/CallViewModel.kt +++ b/app/src/main/java/org/linphone/activities/call/viewmodels/CallViewModel.kt @@ -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() diff --git a/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatMessageViewModel.kt b/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatMessageViewModel.kt index 92958055f..cd790ec25 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatMessageViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/viewmodels/ChatMessageViewModel.kt @@ -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 -> {