Skip to content

Commit

Permalink
MediaThumbnailService: fix thumbnail generation on non scraped videos
Browse files Browse the repository at this point in the history
  • Loading branch information
courville committed Dec 7, 2024
1 parent 9c5a931 commit 9853895
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/com/archos/mediaprovider/MediaThumbnailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -146,15 +148,14 @@ 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);
}

@Override
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);
Expand Down Expand Up @@ -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");
}
}

0 comments on commit 9853895

Please sign in to comment.