Skip to content

Commit

Permalink
升级 ExoPlayer 至 2.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Doikki committed Jun 11, 2022
1 parent 0b0310e commit 8a481fc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.32'
ext.kotlin_version = '1.6.21'
repositories {
google()
mavenCentral()
// mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:7.1.2'
// maven publish tool
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.30'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Expand Down
8 changes: 4 additions & 4 deletions constants.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ project.ext {
releaseVersionCode = 53

minSdkVersion = 16
targetSdkVersion = 30
compileSdkVersion = 30
buildToolsVersion = '28.0.3'
targetSdkVersion = 31
compileSdkVersion = 31
buildToolsVersion = '33.0.0'

exoPlayerVersion = '2.14.2'
exoPlayerVersion = '2.17.1'

annotation = 'androidx.annotation:annotation:1.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.LoadControl;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.analytics.DefaultAnalyticsCollector;
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
Expand All @@ -33,7 +33,7 @@
public class ExoMediaPlayer extends AbstractPlayer implements Player.Listener {

protected Context mAppContext;
protected SimpleExoPlayer mInternalPlayer;
protected ExoPlayer mInternalPlayer;
protected MediaSource mMediaSource;
protected ExoMediaSourceHelper mMediaSourceHelper;

Expand All @@ -52,14 +52,14 @@ public ExoMediaPlayer(Context context) {

@Override
public void initPlayer() {
mInternalPlayer = new SimpleExoPlayer.Builder(
mInternalPlayer = new ExoPlayer.Builder(
mAppContext,
mRenderersFactory == null ? mRenderersFactory = new DefaultRenderersFactory(mAppContext) : mRenderersFactory,
mTrackSelector == null ? mTrackSelector = new DefaultTrackSelector(mAppContext) : mTrackSelector,
new DefaultMediaSourceFactory(mAppContext),
mTrackSelector == null ? mTrackSelector = new DefaultTrackSelector(mAppContext) : mTrackSelector,
mLoadControl == null ? mLoadControl = new DefaultLoadControl() : mLoadControl,
DefaultBandwidthMeter.getSingletonInstance(mAppContext),
new AnalyticsCollector(Clock.DEFAULT))
new DefaultAnalyticsCollector(Clock.DEFAULT))
.build();
setOptions();

Expand Down Expand Up @@ -268,11 +268,13 @@ public void onPlaybackStateChanged(int playbackState) {
case Player.STATE_ENDED:
mPlayerEventListener.onCompletion();
break;
case Player.STATE_IDLE:
break;
}
}

@Override
public void onPlayerError(ExoPlaybackException error) {
public void onPlayerError(PlaybackException error) {
if (mPlayerEventListener != null) {
mPlayerEventListener.onError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.database.ExoDatabaseProvider;
import com.google.android.exoplayer2.ext.rtmp.RtmpDataSourceFactory;
import com.google.android.exoplayer2.database.StandaloneDatabaseProvider;
import com.google.android.exoplayer2.ext.rtmp.RtmpDataSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.source.rtsp.RtspMediaSource;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultDataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.cache.Cache;
Expand All @@ -29,7 +29,7 @@

public final class ExoMediaSourceHelper {

private static ExoMediaSourceHelper sInstance;
private static volatile ExoMediaSourceHelper sInstance;

private final String mUserAgent;
private final Context mAppContext;
Expand Down Expand Up @@ -67,7 +67,7 @@ public MediaSource getMediaSource(String uri, boolean isCache) {
public MediaSource getMediaSource(String uri, Map<String, String> headers, boolean isCache) {
Uri contentUri = Uri.parse(uri);
if ("rtmp".equals(contentUri.getScheme())) {
return new ProgressiveMediaSource.Factory(new RtmpDataSourceFactory(null))
return new ProgressiveMediaSource.Factory(new RtmpDataSource.Factory())
.createMediaSource(MediaItem.fromUri(contentUri));
} else if ("rtsp".equals(contentUri.getScheme())) {
return new RtspMediaSource.Factory().createMediaSource(MediaItem.fromUri(contentUri));
Expand Down Expand Up @@ -118,7 +118,7 @@ private Cache newCache() {
return new SimpleCache(
new File(mAppContext.getExternalCacheDir(), "exo-video-cache"),//缓存目录
new LeastRecentlyUsedCacheEvictor(512 * 1024 * 1024),//缓存大小,默认512M,使用LRU算法实现
new ExoDatabaseProvider(mAppContext));
new StandaloneDatabaseProvider(mAppContext));
}

/**
Expand All @@ -127,7 +127,7 @@ private Cache newCache() {
* @return A new DataSource factory.
*/
private DataSource.Factory getDataSourceFactory() {
return new DefaultDataSourceFactory(mAppContext, getHttpDataSourceFactory());
return new DefaultDataSource.Factory(mAppContext, getHttpDataSourceFactory());
}

/**
Expand Down
4 changes: 3 additions & 1 deletion dkplayer-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:name=".app.MyApplication"
Expand Down Expand Up @@ -35,6 +35,7 @@
<activity
android:name=".activity.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -49,6 +50,7 @@
<activity
android:name=".activity.api.PlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
android:exported="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter tools:ignore="AppLinkUrlError">
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Apr 20 23:16:41 CST 2021
#Sat Jun 11 20:36:29 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
zipStoreBase=GRADLE_USER_HOME

0 comments on commit 8a481fc

Please sign in to comment.