Use speaker sound card if available to play call recordings
This commit is contained in:
parent
bb5903f72c
commit
e204e8d990
2 changed files with 25 additions and 4 deletions
|
@ -26,10 +26,12 @@ import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
|
import org.linphone.core.AudioDevice
|
||||||
import org.linphone.core.Player
|
import org.linphone.core.Player
|
||||||
import org.linphone.core.PlayerListener
|
import org.linphone.core.PlayerListener
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
|
import org.linphone.utils.LinphoneUtils
|
||||||
|
|
||||||
class RecordingViewModel(val path: String) : ViewModel(), Comparable<RecordingViewModel> {
|
class RecordingViewModel(val path: String) : ViewModel(), Comparable<RecordingViewModel> {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -64,13 +66,26 @@ class RecordingViewModel(val path: String) : ViewModel(), Comparable<RecordingVi
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val m = RECORD_PATTERN.matcher(path)
|
val m = RECORD_PATTERN.matcher(path)
|
||||||
if (m.matches()) {
|
if (m.matches() && m.groupCount() >= 2) {
|
||||||
name = m.group(1)
|
name = m.group(1)
|
||||||
date = SimpleDateFormat("dd-MM-yyyy-HH-mm-ss", Locale.getDefault()).parse(m.group(2))
|
date = LinphoneUtils.getRecordingDateFromFileName(m.group(2))
|
||||||
}
|
}
|
||||||
isPlaying.value = false
|
isPlaying.value = false
|
||||||
|
|
||||||
player = coreContext.core.createLocalPlayer(null, null, null)
|
// Use speaker sound card to play recordings, otherwise use earpiece
|
||||||
|
// If none are available, default one will be used
|
||||||
|
var speakerCard: String? = null
|
||||||
|
var earpieceCard: String? = null
|
||||||
|
for (device in coreContext.core.audioDevices) {
|
||||||
|
if (device.hasCapability(AudioDevice.Capabilities.CapabilityPlay)) {
|
||||||
|
if (device.type == AudioDevice.Type.Speaker) {
|
||||||
|
speakerCard = device.id
|
||||||
|
} else if (device.type == AudioDevice.Type.Earpiece) {
|
||||||
|
earpieceCard = device.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player = coreContext.core.createLocalPlayer(speakerCard ?: earpieceCard, null, null)
|
||||||
player.addListener(listener)
|
player.addListener(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@ import org.linphone.core.tools.Log
|
||||||
*/
|
*/
|
||||||
class LinphoneUtils {
|
class LinphoneUtils {
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val RECORDING_DATE_PATTERN = "dd-MM-yyyy-HH-mm-ss"
|
||||||
|
|
||||||
fun getDisplayName(address: Address): String {
|
fun getDisplayName(address: Address): String {
|
||||||
return address.displayName ?: address.username
|
return address.displayName ?: address.username
|
||||||
}
|
}
|
||||||
|
@ -99,9 +101,13 @@ class LinphoneUtils {
|
||||||
|
|
||||||
fun getRecordingFilePathForAddress(address: Address): String {
|
fun getRecordingFilePathForAddress(address: Address): String {
|
||||||
val displayName = getDisplayName(address)
|
val displayName = getDisplayName(address)
|
||||||
val dateFormat: DateFormat = SimpleDateFormat("dd-MM-yyyy-HH-mm-ss", Locale.getDefault())
|
val dateFormat: DateFormat = SimpleDateFormat(RECORDING_DATE_PATTERN, Locale.getDefault())
|
||||||
val fileName = "${displayName}_${dateFormat.format(Date())}.mkv"
|
val fileName = "${displayName}_${dateFormat.format(Date())}.mkv"
|
||||||
return FileUtils.getFileStoragePath(fileName).absolutePath
|
return FileUtils.getFileStoragePath(fileName).absolutePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getRecordingDateFromFileName(name: String): Date {
|
||||||
|
return SimpleDateFormat(RECORDING_DATE_PATTERN, Locale.getDefault()).parse(name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue