-Removed redundant track removal after playing.
-Reverted thumbnail loader to use ImageLoader.
This commit is contained in:
parent
150c3b413a
commit
53cec61cdf
|
@ -173,11 +173,6 @@ public class BackgroundPlayer extends Service {
|
|||
}
|
||||
|
||||
private void setupNotification(RemoteViews remoteViews) {
|
||||
//if (videoThumbnail != null) remoteViews.setImageViewBitmap(R.id.notificationCover, videoThumbnail);
|
||||
///else remoteViews.setImageViewResource(R.id.notificationCover, R.drawable.dummy_thumbnail);
|
||||
// remoteViews.setTextViewText(R.id.notificationSongName, basePlayerImpl.getVideoTitle());
|
||||
// remoteViews.setTextViewText(R.id.notificationArtist, basePlayerImpl.getUploaderName());
|
||||
|
||||
remoteViews.setOnClickPendingIntent(R.id.notificationPlayPause,
|
||||
PendingIntent.getBroadcast(this, NOTIFICATION_ID, new Intent(ACTION_PLAY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT));
|
||||
remoteViews.setOnClickPendingIntent(R.id.notificationStop,
|
||||
|
@ -213,7 +208,7 @@ public class BackgroundPlayer extends Service {
|
|||
* @param drawableId if != -1, sets the drawable with that id on the play/pause button
|
||||
*/
|
||||
private synchronized void updateNotification(int drawableId) {
|
||||
if (DEBUG) Log.d(TAG, "updateNotification() called with: drawableId = [" + drawableId + "]");
|
||||
//if (DEBUG) Log.d(TAG, "updateNotification() called with: drawableId = [" + drawableId + "]");
|
||||
if (notBuilder == null) return;
|
||||
if (drawableId != -1) {
|
||||
if (notRemoteView != null) notRemoteView.setImageViewResource(R.id.notificationPlayPause, drawableId);
|
||||
|
@ -287,14 +282,11 @@ public class BackgroundPlayer extends Service {
|
|||
super.onThumbnailReceived(thumbnail);
|
||||
|
||||
if (thumbnail != null) {
|
||||
videoThumbnail = thumbnail;
|
||||
|
||||
// rebuild notification here since remote view does not release bitmaps, causing memory leaks
|
||||
// remove this line to see for yourself
|
||||
notBuilder = createNotification();
|
||||
|
||||
if (notRemoteView != null) notRemoteView.setImageViewBitmap(R.id.notificationCover, videoThumbnail);
|
||||
if (bigNotRemoteView != null) bigNotRemoteView.setImageViewBitmap(R.id.notificationCover, videoThumbnail);
|
||||
if (notRemoteView != null) notRemoteView.setImageViewBitmap(R.id.notificationCover, thumbnail);
|
||||
if (bigNotRemoteView != null) bigNotRemoteView.setImageViewBitmap(R.id.notificationCover, thumbnail);
|
||||
|
||||
updateNotification(-1);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import android.net.Uri;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.DefaultLoadControl;
|
||||
|
@ -64,6 +65,7 @@ import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvicto
|
|||
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
|
||||
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.R;
|
||||
|
@ -85,19 +87,15 @@ import java.util.ArrayList;
|
|||
import java.util.Formatter;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleObserver;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.disposables.SerialDisposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.functions.Predicate;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Base for the players, joining the common properties
|
||||
|
@ -138,7 +136,6 @@ public abstract class BasePlayer implements Player.EventListener,
|
|||
public static final String RESTORE_QUEUE_INDEX = "restore_queue_index";
|
||||
public static final String RESTORE_WINDOW_POS = "restore_window_pos";
|
||||
|
||||
protected Bitmap videoThumbnail = null;
|
||||
protected String videoUrl = "";
|
||||
protected String videoTitle = "";
|
||||
protected String videoThumbnailUrl = "";
|
||||
|
@ -168,11 +165,9 @@ public abstract class BasePlayer implements Player.EventListener,
|
|||
protected final DefaultExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
|
||||
protected final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
|
||||
|
||||
protected int PROGRESS_LOOP_INTERVAL = 100;
|
||||
protected int PROGRESS_LOOP_INTERVAL = 500;
|
||||
protected Disposable progressUpdateReactor;
|
||||
|
||||
protected SerialDisposable thumbnailReactor;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
public BasePlayer(Context context) {
|
||||
|
@ -189,8 +184,6 @@ public abstract class BasePlayer implements Player.EventListener,
|
|||
this.intentFilter = new IntentFilter();
|
||||
setupBroadcastReceiver(intentFilter);
|
||||
context.registerReceiver(broadcastReceiver, intentFilter);
|
||||
|
||||
this.thumbnailReactor = new SerialDisposable();
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
|
@ -301,34 +294,20 @@ public abstract class BasePlayer implements Player.EventListener,
|
|||
}
|
||||
|
||||
public void initThumbnail(final String url) {
|
||||
final Callable<Bitmap> bitmapCallable = new Callable<Bitmap>() {
|
||||
if (DEBUG) Log.d(TAG, "initThumbnail() called");
|
||||
if (url == null || url.isEmpty()) return;
|
||||
ImageLoader.getInstance().resume();
|
||||
ImageLoader.getInstance().loadImage(url, new SimpleImageLoadingListener() {
|
||||
@Override
|
||||
public Bitmap call() throws Exception {
|
||||
return ImageLoader.getInstance().loadImageSync(url);
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
if (simpleExoPlayer == null) return;
|
||||
if (DEBUG) Log.d(TAG, "onLoadingComplete() called with: imageUri = [" + imageUri + "], view = [" + view + "], loadedImage = [" + loadedImage + "]");
|
||||
onThumbnailReceived(loadedImage);
|
||||
}
|
||||
};
|
||||
|
||||
Single.fromCallable(bitmapCallable)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new SingleObserver<Bitmap>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
thumbnailReactor.set(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(@NonNull Bitmap bitmap) {
|
||||
onThumbnailReceived(bitmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e(TAG, "Thumbnail Fetch Failed.", e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void onThumbnailReceived(Bitmap thumbnail) {
|
||||
if (DEBUG) Log.d(TAG, "onThumbnailReceived() called with: thumbnail = [" + thumbnail + "]");
|
||||
}
|
||||
|
@ -351,10 +330,6 @@ public abstract class BasePlayer implements Player.EventListener,
|
|||
destroyPlayer();
|
||||
unregisterBroadcastReceiver();
|
||||
|
||||
thumbnailReactor.dispose();
|
||||
thumbnailReactor = null;
|
||||
videoThumbnail = null;
|
||||
|
||||
simpleExoPlayer = null;
|
||||
}
|
||||
|
||||
|
@ -891,14 +866,6 @@ public abstract class BasePlayer implements Player.EventListener,
|
|||
isPrepared = prepared;
|
||||
}
|
||||
|
||||
public Bitmap getVideoThumbnail() {
|
||||
return videoThumbnail;
|
||||
}
|
||||
|
||||
public void setVideoThumbnail(Bitmap videoThumbnail) {
|
||||
this.videoThumbnail = videoThumbnail;
|
||||
}
|
||||
|
||||
public String getVideoThumbnailUrl() {
|
||||
return videoThumbnailUrl;
|
||||
}
|
||||
|
|
|
@ -83,9 +83,6 @@ public class PlaybackManager {
|
|||
public void refresh(final int newSourceIndex) {
|
||||
if (sourceToQueueIndex.indexOf(newSourceIndex) != -1 && newSourceIndex == getCurrentSourceIndex() + 1) {
|
||||
playQueue.offsetIndex(+1);
|
||||
|
||||
// free up some memory
|
||||
if (sourceToQueueIndex.size() > 1) remove(sourceToQueueIndex.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,9 +160,7 @@ public class PlaybackManager {
|
|||
remove(removeEvent.index());
|
||||
break;
|
||||
case MOVE:
|
||||
final MoveEvent moveEvent = (MoveEvent) event;
|
||||
move(moveEvent.getFrom(), moveEvent.getTo());
|
||||
break;
|
||||
throw new UnsupportedOperationException("Move not yet supported");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -340,17 +335,4 @@ public class PlaybackManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void move(final int source, final int target) {
|
||||
final int sourceIndex = sourceToQueueIndex.indexOf(source);
|
||||
final int targetIndex = sourceToQueueIndex.indexOf(target);
|
||||
|
||||
if (sourceIndex != -1 && targetIndex != -1) {
|
||||
sources.moveMediaSource(sourceIndex, targetIndex);
|
||||
} else if (sourceIndex != -1) {
|
||||
remove(sourceIndex);
|
||||
} else if (targetIndex != -1) {
|
||||
remove(targetIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue