mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Prevent crash first time app is installed due to chat message notification sound not installed yet
This commit is contained in:
parent
977fb63693
commit
a392cf3a6b
1 changed files with 22 additions and 20 deletions
|
|
@ -125,7 +125,7 @@ class NotificationsManager
|
|||
private var currentlyDisplayedChatRoomId: String = ""
|
||||
private var currentlyDisplayedIncomingCallFragment: Boolean = false
|
||||
|
||||
private val mediaPlayer: MediaPlayer
|
||||
private lateinit var mediaPlayer: MediaPlayer
|
||||
|
||||
private val contactsListener = object : ContactsListener {
|
||||
@WorkerThread
|
||||
|
|
@ -446,21 +446,6 @@ class NotificationsManager
|
|||
previousChatNotifications.add(notification.id)
|
||||
}
|
||||
}
|
||||
|
||||
val soundPath = corePreferences.messageReceivedInVisibleConversationNotificationSound
|
||||
mediaPlayer = MediaPlayer().apply {
|
||||
setAudioAttributes(
|
||||
AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
||||
.build()
|
||||
)
|
||||
setDataSource(soundPath)
|
||||
try {
|
||||
prepare()
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Failed to prepare message received sound file [$soundPath]: $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
|
|
@ -554,6 +539,21 @@ class NotificationsManager
|
|||
core.addListener(coreListener)
|
||||
|
||||
coreContext.contactsManager.addListener(contactsListener)
|
||||
|
||||
val soundPath = corePreferences.messageReceivedInVisibleConversationNotificationSound
|
||||
mediaPlayer = MediaPlayer().apply {
|
||||
try {
|
||||
setAudioAttributes(
|
||||
AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
||||
.build()
|
||||
)
|
||||
setDataSource(soundPath)
|
||||
prepare()
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Failed to prepare message received sound file [$soundPath]: $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
@ -1627,10 +1627,12 @@ class NotificationsManager
|
|||
|
||||
@WorkerThread
|
||||
private fun playMessageReceivedSound() {
|
||||
try {
|
||||
mediaPlayer.start()
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Failed to play message received sound file: $e")
|
||||
if (::mediaPlayer.isInitialized) {
|
||||
try {
|
||||
mediaPlayer.start()
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Failed to play message received sound file: $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue