From 985389580030f905b2eb76895cf4a4985359601b Mon Sep 17 00:00:00 2001 From: Courville Software Date: Sat, 7 Dec 2024 19:18:38 +0100 Subject: [PATCH] MediaThumbnailService: fix thumbnail generation on non scraped videos See https://github.com/nova-video-player/aos-AVP/issues/1324 --- .../mediaprovider/MediaThumbnailService.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/com/archos/mediaprovider/MediaThumbnailService.java b/src/com/archos/mediaprovider/MediaThumbnailService.java index c8e95c05..b3c98293 100644 --- a/src/com/archos/mediaprovider/MediaThumbnailService.java +++ b/src/com/archos/mediaprovider/MediaThumbnailService.java @@ -24,7 +24,6 @@ import android.os.IBinder; import android.os.Looper; import android.os.Message; -import android.util.Log; import android.widget.Toast; import androidx.lifecycle.DefaultLifecycleObserver; @@ -35,12 +34,16 @@ import com.archos.medialib.IMediaMetadataRetriever; import com.archos.medialib.MediaFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.lang.ref.WeakReference; public class MediaThumbnailService extends Service implements DefaultLifecycleObserver { + private static final Logger log = LoggerFactory.getLogger(MediaThumbnailService.class); + private static boolean sFirst = true; - private static final boolean DBG = false; static class ServiceStub extends IMediaThumbnailService.Stub { MediaThumbnailService mService; @@ -89,12 +92,12 @@ public void handleMessage(Message msg) { static private final ServiceConnection mServiceConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { - if (DBG) Log.d(TAG, "onServiceDisconnected"); + log.debug("onServiceDisconnected"); sMediaThumbnailService = null; } public void onServiceConnected(ComponentName name, IBinder service) { - if (DBG) Log.d(TAG, "onServiceConnected: " + name); + log.debug("onServiceConnected: {}", name); synchronized (sLock) { sMediaThumbnailService = IMediaThumbnailService.Stub.asInterface(service); sLock.notifyAll(); @@ -123,20 +126,19 @@ public static IMediaThumbnailService bind_sync(Context ctx) { bind(ctx); if (sMediaThumbnailService == null) { try { - if (DBG) Log.d(TAG, "sMediaThumbnailService == null"); + log.debug("sMediaThumbnailService == null"); sLock.wait(3000); if(sMediaThumbnailService == null&&sFirst) { Toast.makeText(ArchosUtils.getGlobalContext(), "timeout: sMediaThumbnailService == null", Toast.LENGTH_LONG).show(); sFirst = false; } - if (DBG) Log.d(TAG, "bind_sync end of wait : sMediaThumbnailService == null "+(sMediaThumbnailService == null)); + log.debug("bind_sync end of wait : sMediaThumbnailService == null "+(sMediaThumbnailService == null)); } catch (InterruptedException e) { - Log.w(TAG, "bind_sync interrupted"); if(sFirst) Toast.makeText(ArchosUtils.getGlobalContext(), "bind_sync interrupted", Toast.LENGTH_LONG).show(); sFirst = false; - e.printStackTrace(); + log.error("bind_sync interrupted", e); } } return sMediaThumbnailService; @@ -146,7 +148,7 @@ public static IMediaThumbnailService bind_sync(Context ctx) { @Override public void onCreate() { super.onCreate(); - if (DBG) Log.d(TAG, "onCreate"); + log.debug("onCreate"); ProcessLifecycleOwner.get().getLifecycle().addObserver(this); } @@ -154,7 +156,6 @@ public void onCreate() { public void onDestroy() { if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); // Clear any pending messages from the handler - mHandler = null; } // Unbind from the service connection if it's still bound release(this); @@ -195,12 +196,12 @@ public Bitmap getThumbnail(String path, int timeUs) { public void onStop(LifecycleOwner owner) { // App in background - Log.d(TAG, "onStop: LifecycleOwner App in background"); + log.debug("onStop: LifecycleOwner App in background"); stopSelf(); } public void onStart(LifecycleOwner owner) { // App in foreground - Log.d(TAG, "onStart: LifecycleOwner App in foreground"); + log.debug("onStart: LifecycleOwner App in foreground"); } }