diff --git a/app/src/main/java/org/linphone/ui/fileviewer/viewmodel/MediaViewModel.kt b/app/src/main/java/org/linphone/ui/fileviewer/viewmodel/MediaViewModel.kt
index d7a0a8ce5..eecc3ffe0 100644
--- a/app/src/main/java/org/linphone/ui/fileviewer/viewmodel/MediaViewModel.kt
+++ b/app/src/main/java/org/linphone/ui/fileviewer/viewmodel/MediaViewModel.kt
@@ -34,6 +34,7 @@ import org.linphone.ui.GenericViewModel
import org.linphone.utils.Event
import org.linphone.utils.FileUtils
import org.linphone.utils.TimestampUtils
+import org.linphone.R
class MediaViewModel
@UiThread
@@ -163,33 +164,40 @@ class MediaViewModel
private fun initMediaPlayer() {
isMediaPlaying.value = false
- mediaPlayer = MediaPlayer().apply {
- setAudioAttributes(
- AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).setUsage(
- AudioAttributes.USAGE_MEDIA
- ).build()
- )
- setDataSource(filePath)
- setOnCompletionListener {
- Log.i("$TAG Media player reached the end of file")
- isMediaPlaying.postValue(false)
- position.postValue(0)
- stopUpdatePlaybackPosition()
+ try {
+ mediaPlayer = MediaPlayer().apply {
+ setAudioAttributes(
+ AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
+ .setUsage(
+ AudioAttributes.USAGE_MEDIA
+ ).build()
+ )
+ setDataSource(filePath)
+ setOnCompletionListener {
+ Log.i("$TAG Media player reached the end of file")
+ isMediaPlaying.postValue(false)
+ position.postValue(0)
+ stopUpdatePlaybackPosition()
- // Leave full screen when playback is done
- fullScreenMode.postValue(false)
- changeFullScreenModeEvent.postValue(Event(false))
- }
- setOnVideoSizeChangedListener { mediaPlayer, width, height ->
- videoSizeChangedEvent.postValue(Event(Pair(width, height)))
- }
- try {
- prepare()
- } catch (e: Exception) {
- fullScreenMode.postValue(false)
- changeFullScreenModeEvent.postValue(Event(false))
- Log.e("$TAG Failed to prepare video file: $e")
+ // Leave full screen when playback is done
+ fullScreenMode.postValue(false)
+ changeFullScreenModeEvent.postValue(Event(false))
+ }
+ setOnVideoSizeChangedListener { mediaPlayer, width, height ->
+ videoSizeChangedEvent.postValue(Event(Pair(width, height)))
+ }
+ try {
+ prepare()
+ } catch (e: Exception) {
+ fullScreenMode.postValue(false)
+ changeFullScreenModeEvent.postValue(Event(false))
+ Log.e("$TAG Failed to prepare video file: $e")
+ }
}
+ } catch (e: Exception) {
+ Log.e("$TAG Failed to initialize media player for file [$filePath]: $e")
+ showRedToast(R.string.media_player_generic_error_toast, R.drawable.warning_circle)
+ return
}
val durationInMillis = mediaPlayer.duration
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index d7557d089..22f3c3670 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -90,6 +90,7 @@
Volume faible : vous risquez de ne pas entendre
Configuration appliquée
Erreur lors du chargement ou de l\'application de la configuration
+ Erreur lors de la création du lecteur média
Conditions de service & politique de confidentialité
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f66b4bbed..567b02e0a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -129,6 +129,7 @@
Media volume is low, you may not hear anything!
Configuration successfully applied
Error while trying to download and apply remote configuration
+ Error trying to create media player
General terms & privacy policy