Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
BC
public
linphone-android
Merge requests
!1795
Prevent crash if MediaPlayer can't be instancianted
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Sylvain Berfini
requested to merge
fix/prevent_crash_mediaplayer
into
release/6.0
3 weeks ago
Overview
0
Commits
1
Pipelines
1
Changes
3
0
0
Compare
release/6.0
release/6.0 (base)
and
latest version
latest version
0bf6d605
1 commit,
3 weeks ago
3 files
+
36
−
26
Expand all files
Preferences
Preferences
File browser
List view
Tree view
Compare changes
Inline
Side-by-side
Show whitespace changes
Show one file at a time
Search (e.g. *.vue) (Ctrl+P)
app/src/main/java/org/linphone/ui/fileviewer/viewmodel/MediaViewModel.kt
+
34
−
26
Options
View file @ 0bf6d605
Edit in single-file editor
Open in Web IDE
Show full file
@@ -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
()
// 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"
)
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"
)
}
}
}
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
app/src/main/res/values/strings.xml
+
1
−
0
Options
View file @ 0bf6d605
Edit in single-file editor
Open in Web IDE
Show full file
@@ -129,6 +129,7 @@
<string
name=
"media_playback_low_volume_warning_toast"
>
Media volume is low, you may not hear anything!
</string>
<string
name=
"remote_provisioning_config_applied_toast"
>
Configuration successfully applied
</string>
<string
name=
"remote_provisioning_config_failed_toast"
>
Error while trying to download and apply remote configuration
</string>
<string
name=
"media_player_generic_error_toast"
>
Error trying to create media player
</string>
<!-- Assistant related string (account register / login / etc...) -->
<string
name=
"assistant_dialog_general_terms_and_privacy_policy_title"
>
General terms
&
privacy policy
</string>
app/src/main/res/values-fr/strings.xml
+
1
−
0
Options
View file @ 0bf6d605
Edit in single-file editor
Open in Web IDE
Show full file
@@ -90,6 +90,7 @@
<string
name=
"media_playback_low_volume_warning_toast"
>
Volume faible : vous risquez de ne pas entendre
</string>
<string
name=
"remote_provisioning_config_applied_toast"
>
Configuration appliquée
</string>
<string
name=
"remote_provisioning_config_failed_toast"
>
Erreur lors du chargement ou de l\'application de la configuration
</string>
<string
name=
"media_player_generic_error_toast"
>
Erreur lors de la création du lecteur média
</string>
<!-- Assistant related string (account register / login / etc...) -->
<string
name=
"assistant_dialog_general_terms_and_privacy_policy_title"
>
Conditions de service
&
politique de confidentialité
</string>
Menu
Explore
Projects
Groups
Topics
Snippets