Display warning when playing voice message if media volume is low
This commit is contained in:
parent
81104a31de
commit
bfbae245ce
4 changed files with 24 additions and 0 deletions
|
@ -24,6 +24,7 @@ import android.text.Spannable
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
import android.text.style.UnderlineSpan
|
import android.text.style.UnderlineSpan
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -292,6 +293,11 @@ class ChatMessageContentData(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log.i("[Voice Recording] Found speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
|
||||||
|
|
||||||
|
if (AppUtils.isMediaVolumeLow(coreContext.context)) {
|
||||||
|
Toast.makeText(coreContext.context, R.string.chat_message_voice_recording_playback_low_volume, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
|
||||||
val localPlayer = coreContext.core.createLocalPlayer(speakerCard ?: earpieceCard, null, null)
|
val localPlayer = coreContext.core.createLocalPlayer(speakerCard ?: earpieceCard, null, null)
|
||||||
if (localPlayer != null) {
|
if (localPlayer != null) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package org.linphone.activities.main.chat.viewmodels
|
package org.linphone.activities.main.chat.viewmodels
|
||||||
|
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
@ -32,10 +33,12 @@ import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||||
|
import org.linphone.R
|
||||||
import org.linphone.activities.main.chat.data.ChatMessageAttachmentData
|
import org.linphone.activities.main.chat.data.ChatMessageAttachmentData
|
||||||
import org.linphone.activities.main.chat.data.ChatMessageData
|
import org.linphone.activities.main.chat.data.ChatMessageData
|
||||||
import org.linphone.core.*
|
import org.linphone.core.*
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
|
import org.linphone.utils.AppUtils
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
import org.linphone.utils.FileUtils
|
import org.linphone.utils.FileUtils
|
||||||
import org.linphone.utils.PermissionHelper
|
import org.linphone.utils.PermissionHelper
|
||||||
|
@ -381,6 +384,11 @@ class ChatMessageSendingViewModel(private val chatRoom: ChatRoom) : ViewModel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log.i("[Chat Message Sending] Found speaker sound card [$speakerCard] and earpiece sound card [$earpieceCard]")
|
||||||
|
|
||||||
|
if (AppUtils.isMediaVolumeLow(coreContext.context)) {
|
||||||
|
Toast.makeText(coreContext.context, R.string.chat_message_voice_recording_playback_low_volume, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
|
||||||
val localPlayer = coreContext.core.createLocalPlayer(speakerCard ?: earpieceCard, null, null)
|
val localPlayer = coreContext.core.createLocalPlayer(speakerCard ?: earpieceCard, null, null)
|
||||||
if (localPlayer != null) {
|
if (localPlayer != null) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.app.Activity
|
||||||
import android.content.ActivityNotFoundException
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.media.AudioManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.format.Formatter.formatShortFileSize
|
import android.text.format.Formatter.formatShortFileSize
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
|
@ -131,5 +132,13 @@ class AppUtils {
|
||||||
|
|
||||||
return bundle
|
return bundle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isMediaVolumeLow(context: Context): Boolean {
|
||||||
|
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
|
val currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
|
||||||
|
val maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)
|
||||||
|
Log.i("[Media Volume] Current value is $currentVolume, max value is $maxVolume")
|
||||||
|
return currentVolume <= maxVolume * 0.5
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,6 +219,7 @@
|
||||||
<string name="chat_room_sending_reply_hint">Reply</string>
|
<string name="chat_room_sending_reply_hint">Reply</string>
|
||||||
<string name="chat_room_sending_message_hint">Message</string>
|
<string name="chat_room_sending_message_hint">Message</string>
|
||||||
<string name="chat_message_voice_recording_hold_to_record">Hold button to record voice message</string>
|
<string name="chat_message_voice_recording_hold_to_record">Hold button to record voice message</string>
|
||||||
|
<string name="chat_message_voice_recording_playback_low_volume">Your media volume is low, you may want to increase it</string>
|
||||||
|
|
||||||
<!-- Recordings -->
|
<!-- Recordings -->
|
||||||
<string name="recordings_empty_list">No recordings</string>
|
<string name="recordings_empty_list">No recordings</string>
|
||||||
|
|
Loading…
Reference in a new issue