[Android] Improve playback error toast display conditions

Nicolas Pomepuy git at videolan.org
Thu Feb 3 07:38:54 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Feb  2 08:03:40 2022 +0100| [ce3e79786d5f011eda13f060c61e576a75d1fe9e] | committer: Nicolas Pomepuy

Improve playback error toast display conditions

> https://code.videolan.org/videolan/vlc-android/commit/ce3e79786d5f011eda13f060c61e576a75d1fe9e
---

 application/vlc-android/src/org/videolan/vlc/PlaybackService.kt | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 28ac660a7..54df829cc 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -19,6 +19,7 @@
 
 package org.videolan.vlc
 
+import android.annotation.SuppressLint
 import android.annotation.TargetApi
 import android.app.*
 import android.appwidget.AppWidgetManager
@@ -793,8 +794,10 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
     private class PlaybackServiceHandler(owner: PlaybackService) : WeakHandler<PlaybackService>(owner) {
 
         var currentToast: Toast? = null
+        var lastErrorTime = 0L
         var nbErrors = 0
 
+        @SuppressLint("ShowToast")
         override fun handleMessage(msg: Message) {
             val service = owner ?: return
             when (msg.what) {
@@ -805,11 +808,12 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                     val isError = bundle.getBoolean("isError")
                     if (isError) {
                         when {
-                            nbErrors > 5 -> return
-                            nbErrors == 5 -> text = service.getString(R.string.playback_multiple_errors)
+                            nbErrors > 2 && System.currentTimeMillis() - lastErrorTime < 500 -> return
+                            nbErrors >= 2 -> text = service.getString(R.string.playback_multiple_errors)
                         }
                         currentToast?.cancel()
                         nbErrors++
+                        lastErrorTime = System.currentTimeMillis()
                     }
                     currentToast = Toast.makeText(AppContextProvider.appContext, text, duration)
                     currentToast?.show()



More information about the Android mailing list