Fix seekbar invisible or not updating
Have the notification recreate only when strictly necessary, and recreate it if there was a timeline change, fixing the seekbar not updating at all sometimes
This commit is contained in:
parent
5846fbabce
commit
bccfe500b3
2 changed files with 14 additions and 6 deletions
|
@ -78,10 +78,7 @@ public final class NotificationUtil {
|
||||||
*/
|
*/
|
||||||
synchronized void createNotificationIfNeededAndUpdate(final VideoPlayerImpl player,
|
synchronized void createNotificationIfNeededAndUpdate(final VideoPlayerImpl player,
|
||||||
final boolean forceRecreate) {
|
final boolean forceRecreate) {
|
||||||
if (notificationBuilder == null || forceRecreate) {
|
if (forceRecreate || notificationBuilder == null) {
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "N_ createNotificationIfNeededAndUpdate(true)");
|
|
||||||
}
|
|
||||||
notificationBuilder = createNotification(player);
|
notificationBuilder = createNotification(player);
|
||||||
}
|
}
|
||||||
updateNotification(player);
|
updateNotification(player);
|
||||||
|
@ -89,6 +86,9 @@ public final class NotificationUtil {
|
||||||
|
|
||||||
private synchronized NotificationCompat.Builder createNotification(
|
private synchronized NotificationCompat.Builder createNotification(
|
||||||
final VideoPlayerImpl player) {
|
final VideoPlayerImpl player) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "createNotification()");
|
||||||
|
}
|
||||||
notificationManager =
|
notificationManager =
|
||||||
(NotificationManager) player.context.getSystemService(NOTIFICATION_SERVICE);
|
(NotificationManager) player.context.getSystemService(NOTIFICATION_SERVICE);
|
||||||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(player.context,
|
final NotificationCompat.Builder builder = new NotificationCompat.Builder(player.context,
|
||||||
|
@ -132,7 +132,7 @@ public final class NotificationUtil {
|
||||||
*/
|
*/
|
||||||
private synchronized void updateNotification(final VideoPlayerImpl player) {
|
private synchronized void updateNotification(final VideoPlayerImpl player) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "N_ updateNotification()");
|
Log.d(TAG, "updateNotification()");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notificationBuilder == null) {
|
if (notificationBuilder == null) {
|
||||||
|
@ -158,7 +158,7 @@ public final class NotificationUtil {
|
||||||
|
|
||||||
|
|
||||||
void createNotificationAndStartForeground(final VideoPlayerImpl player, final Service service) {
|
void createNotificationAndStartForeground(final VideoPlayerImpl player, final Service service) {
|
||||||
createNotificationIfNeededAndUpdate(player, true);
|
createNotificationIfNeededAndUpdate(player, false);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
service.startForeground(NOTIFICATION_ID, notificationBuilder.build(),
|
service.startForeground(NOTIFICATION_ID, notificationBuilder.build(),
|
||||||
|
|
|
@ -66,6 +66,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.SimpleExoPlayer;
|
import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||||
|
import com.google.android.exoplayer2.Timeline;
|
||||||
import com.google.android.exoplayer2.source.MediaSource;
|
import com.google.android.exoplayer2.source.MediaSource;
|
||||||
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
import com.google.android.exoplayer2.text.CaptionStyleCompat;
|
||||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||||
|
@ -604,6 +605,13 @@ public class VideoPlayerImpl extends VideoPlayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimelineChanged(final Timeline timeline, final int reason) {
|
||||||
|
super.onTimelineChanged(timeline, reason);
|
||||||
|
// force recreate notification to ensure seek bar is shown when preparation finishes
|
||||||
|
NotificationUtil.getInstance().createNotificationIfNeededAndUpdate(this, true);
|
||||||
|
}
|
||||||
|
|
||||||
protected void onMetadataChanged(@NonNull final MediaSourceTag tag) {
|
protected void onMetadataChanged(@NonNull final MediaSourceTag tag) {
|
||||||
super.onMetadataChanged(tag);
|
super.onMetadataChanged(tag);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue