From 178474e3261263282bd36dcb3574029716005b10 Mon Sep 17 00:00:00 2001 From: jakubhomlala Date: Fri, 9 Jul 2021 15:19:36 +0200 Subject: [PATCH] Updated ExoPlayer version --- CHANGELOG.md | 3 + android/build.gradle | 12 +-- .../jhomlala/better_player/BetterPlayer.java | 79 +++++++++---------- .../jhomlala/better_player/CacheWorker.java | 12 +-- docs/install.md | 2 +- pubspec.yaml | 2 +- 6 files changed, 56 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfcc3c5f1..f1f29b4fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.0.72 +* Updated ExoPlayer version + ## 0.0.71 * Fixed play after seeking issue on iOS. * Fixed audio track selection issue on iOS/Android. diff --git a/android/build.gradle b/android/build.gradle index d5ef1301b..b68cad2f7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -39,12 +39,12 @@ android { } dependencies { - implementation 'com.google.android.exoplayer:exoplayer-core:2.13.3' - implementation 'com.google.android.exoplayer:exoplayer-hls:2.13.3' - implementation 'com.google.android.exoplayer:exoplayer-dash:2.13.3' - implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.13.3' - implementation 'com.google.android.exoplayer:exoplayer-ui:2.13.3' - implementation 'com.google.android.exoplayer:extension-mediasession:2.13.3' + implementation 'com.google.android.exoplayer:exoplayer-core:2.14.1' + implementation 'com.google.android.exoplayer:exoplayer-hls:2.14.1' + implementation 'com.google.android.exoplayer:exoplayer-dash:2.14.1' + implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.14.1' + implementation 'com.google.android.exoplayer:exoplayer-ui:2.14.1' + implementation 'com.google.android.exoplayer:extension-mediasession:2.14.1' implementation "android.arch.lifecycle:runtime:1.1.1" implementation "android.arch.lifecycle:common:1.1.1" implementation "android.arch.lifecycle:common-java8:1.1.1" diff --git a/android/src/main/java/com/jhomlala/better_player/BetterPlayer.java b/android/src/main/java/com/jhomlala/better_player/BetterPlayer.java index 499042ea9..63ef70ea3 100644 --- a/android/src/main/java/com/jhomlala/better_player/BetterPlayer.java +++ b/android/src/main/java/com/jhomlala/better_player/BetterPlayer.java @@ -30,12 +30,12 @@ import com.google.android.exoplayer2.ControlDispatcher; import com.google.android.exoplayer2.DefaultLoadControl; import com.google.android.exoplayer2.ExoPlaybackException; +import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.LoadControl; import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; -import com.google.android.exoplayer2.Player.EventListener; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.audio.AudioAttributes; @@ -104,7 +104,7 @@ final class BetterPlayer { private PlayerNotificationManager playerNotificationManager; private Handler refreshHandler; private Runnable refreshRunnable; - private EventListener exoPlayerEventListener; + private ExoPlayer.Listener exoPlayerEventListener; private Bitmap bitmap; private MediaSessionCompat mediaSession; private DrmSessionManager drmSessionManager; @@ -324,11 +324,10 @@ public Bitmap getCurrentLargeIcon(@NonNull Player player, } } - - playerNotificationManager = new PlayerNotificationManager(context, - playerNotificationChannelName, + playerNotificationManager = new PlayerNotificationManager.Builder(context, NOTIFICATION_ID, - mediaDescriptionAdapter); + playerNotificationChannelName, + mediaDescriptionAdapter).build(); playerNotificationManager.setPlayer(exoPlayer); playerNotificationManager.setUseNextAction(false); playerNotificationManager.setUsePreviousAction(false); @@ -362,7 +361,7 @@ public Bitmap getCurrentLargeIcon(@NonNull Player player, refreshHandler.postDelayed(refreshRunnable, 0); } - exoPlayerEventListener = new EventListener() { + exoPlayerEventListener = new Player.Listener() { @Override public void onPlaybackStateChanged(int playbackState) { mediaSession.setMetadata(new MediaMetadataCompat.Builder() @@ -455,7 +454,9 @@ public boolean isFastForwardEnabled() { public void disposeRemoteNotifications() { - exoPlayer.removeListener(exoPlayerEventListener); + if (exoPlayerEventListener != null) { + exoPlayer.removeListener(exoPlayerEventListener); + } if (refreshHandler != null) { refreshHandler.removeCallbacksAndMessages(null); refreshHandler = null; @@ -552,39 +553,37 @@ public void onCancel(Object o) { exoPlayer.setVideoSurface(surface); setAudioAttributes(exoPlayer, true); - exoPlayer.addListener( - new EventListener() { - - @Override - public void onPlaybackStateChanged(int playbackState) { - if (playbackState == Player.STATE_BUFFERING) { - sendBufferingUpdate(); - Map event = new HashMap<>(); - event.put("event", "bufferingStart"); - eventSink.success(event); - } else if (playbackState == Player.STATE_READY) { - if (!isInitialized) { - isInitialized = true; - sendInitialized(); - } + exoPlayer.addListener(new Player.Listener() { + @Override + public void onPlaybackStateChanged(int playbackState) { + if (playbackState == Player.STATE_BUFFERING) { + sendBufferingUpdate(); + Map event = new HashMap<>(); + event.put("event", "bufferingStart"); + eventSink.success(event); + } else if (playbackState == Player.STATE_READY) { + if (!isInitialized) { + isInitialized = true; + sendInitialized(); + } - Map event = new HashMap<>(); - event.put("event", "bufferingEnd"); - eventSink.success(event); + Map event = new HashMap<>(); + event.put("event", "bufferingEnd"); + eventSink.success(event); - } else if (playbackState == Player.STATE_ENDED) { - Map event = new HashMap<>(); - event.put("event", "completed"); - event.put("key", key); - eventSink.success(event); - } - } + } else if (playbackState == Player.STATE_ENDED) { + Map event = new HashMap<>(); + event.put("event", "completed"); + event.put("key", key); + eventSink.success(event); + } + } - @Override - public void onPlayerError(final ExoPlaybackException error) { - eventSink.error("VideoError", "Video player had error " + error, null); - } - }); + @Override + public void onPlayerError(final ExoPlaybackException error) { + eventSink.error("VideoError", "Video player had error " + error, null); + } + }); Map reply = new HashMap<>(); reply.put("textureId", textureEntry.id()); @@ -601,7 +600,7 @@ void sendBufferingUpdate() { } private void setAudioAttributes(SimpleExoPlayer exoPlayer, Boolean mixWithOthers) { - Player.AudioComponent audioComponent = exoPlayer.getAudioComponent(); + ExoPlayer.AudioComponent audioComponent = exoPlayer.getAudioComponent(); if (audioComponent == null) { return; } @@ -782,7 +781,7 @@ void setAudioTrack(String name, Integer index) { hasElementWithoutLabel = true; } - if (format.id.equals("1/15")) { + if (format.id != null && format.id.equals("1/15")) { hasStrangeAudioTrack = true; } } diff --git a/android/src/main/java/com/jhomlala/better_player/CacheWorker.java b/android/src/main/java/com/jhomlala/better_player/CacheWorker.java index fbae99c2e..f193753f8 100644 --- a/android/src/main/java/com/jhomlala/better_player/CacheWorker.java +++ b/android/src/main/java/com/jhomlala/better_player/CacheWorker.java @@ -70,15 +70,15 @@ public Result doWork() { mCacheWriter = new CacheWriter( cacheDataSourceFactory.createDataSource(), dataSpec, - true, null, (long requestLength, long bytesCached, long newBytesCached) -> { - double completedData = ((bytesCached * 100f) / preCacheSize); - if (completedData >= mLastCacheReportIndex * 10) { - mLastCacheReportIndex += 1; - Log.d(TAG, "Completed pre cache of " + url + ": " + (int) completedData + "%"); + double completedData = ((bytesCached * 100f) / preCacheSize); + if (completedData >= mLastCacheReportIndex * 10) { + mLastCacheReportIndex += 1; + Log.d(TAG, "Completed pre cache of " + url + ": " + (int) completedData + "%"); + } } - }); + ); mCacheWriter.cache(); } else { diff --git a/docs/install.md b/docs/install.md index bdc097861..1beea7585 100644 --- a/docs/install.md +++ b/docs/install.md @@ -4,7 +4,7 @@ ```yaml dependencies: - better_player: ^0.0.71 + better_player: ^0.0.72 ``` 2. Install it diff --git a/pubspec.yaml b/pubspec.yaml index acad11d5f..46e590db1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: better_player description: Advanced video player based on video_player and Chewie. It's solves many typical use cases and it's easy to run. -version: 0.0.71 +version: 0.0.72 authors: - Jakub Homlala homepage: https://github.com/jhomlala/betterplayer