Skip to content

Commit 8c02745

Browse files
feature/support-for-flutter-3-24-3
1 parent ea9e4a3 commit 8c02745

33 files changed

Lines changed: 387 additions & 223 deletions

android/build.gradle

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,55 @@
1-
group 'io.flutter.plugins.videoplayer'
1+
group 'android'
22
version '1.0-SNAPSHOT'
3-
def args = ["-Xlint:deprecation","-Xlint:unchecked","-Werror"]
3+
4+
def args = ["-Xlint:deprecation", "-Xlint:unchecked"]
45

56
buildscript {
7+
ext.kotlin_version = '1.9.22'
68
repositories {
79
google()
8-
jcenter()
10+
mavenCentral()
911
}
1012

1113
dependencies {
12-
classpath 'com.android.tools.build:gradle:7.2.1'
14+
classpath 'com.android.tools.build:gradle:8.3.2'
1315
}
1416
}
1517

16-
rootProject.allprojects {
18+
allprojects {
1719
repositories {
1820
google()
21+
mavenCentral()
1922
}
2023
}
2124

22-
project.getTasks().withType(JavaCompile){
25+
tasks.withType(JavaCompile).configureEach {
2326
options.compilerArgs.addAll(args)
2427
}
2528

2629
apply plugin: 'com.android.library'
2730

2831
android {
29-
compileSdkVersion 33
32+
namespace 'com.lazyarts.vikram.cached_video_player'
33+
compileSdk 34
3034

3135
defaultConfig {
32-
minSdkVersion 16
36+
minSdk 21
3337
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3438
}
35-
lintOptions {
36-
disable 'InvalidPackage'
37-
}
38-
android {
39-
compileOptions {
40-
sourceCompatibility 1.8
41-
targetCompatibility 1.8
42-
}
39+
40+
compileOptions {
41+
sourceCompatibility JavaVersion.VERSION_17
42+
targetCompatibility JavaVersion.VERSION_17
4343
}
4444

45-
dependencies {
46-
implementation 'com.google.android.exoplayer:exoplayer-core:2.17.1'
47-
implementation 'com.google.android.exoplayer:exoplayer-hls:2.17.1'
48-
implementation 'com.google.android.exoplayer:exoplayer-dash:2.17.1'
49-
implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.17.1'
45+
lint {
46+
disable 'InvalidPackage'
5047
}
5148
}
49+
50+
dependencies {
51+
implementation 'com.google.android.exoplayer:exoplayer-core:2.19.1'
52+
implementation 'com.google.android.exoplayer:exoplayer-hls:2.19.1'
53+
implementation 'com.google.android.exoplayer:exoplayer-dash:2.19.1'
54+
implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.19.1'
55+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Wed Oct 17 09:04:56 PDT 2018
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
43
zipStoreBase=GRADLE_USER_HOME
54
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip

android/settings.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
11
rootProject.name = 'cached_video_player'
2+
3+
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4+
def properties = new Properties()
5+
6+
localPropertiesFile.withReader("UTF-8") { reader ->
7+
properties.load(reader)
8+
}
9+
10+
def flutterSdkPath = properties.getProperty("flutter.sdk")
11+
if (flutterSdkPath == null) {
12+
throw new GradleException("flutter.sdk not set in local.properties")
13+
}
14+
15+
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

android/src/main/java/com/lazyarts/vikram/cached_video_player/CacheDataSourceFactory.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.content.Context;
44

5+
import androidx.annotation.NonNull;
6+
57
import com.google.android.exoplayer2.upstream.DataSource;
68
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
79
import com.google.android.exoplayer2.upstream.DefaultDataSource;
@@ -15,10 +17,9 @@
1517

1618
class CacheDataSourceFactory implements DataSource.Factory {
1719
private final Context context;
18-
private DefaultDataSource.Factory defaultDatasourceFactory;
1920
private final long maxFileSize, maxCacheSize;
2021

21-
private DefaultHttpDataSource.Factory defaultHttpDataSourceFactory;
22+
private final DefaultHttpDataSource.Factory defaultHttpDataSourceFactory;
2223

2324
CacheDataSourceFactory(Context context, long maxCacheSize, long maxFileSize) {
2425
super();
@@ -35,11 +36,12 @@ void setHeaders(Map<String, String> httpHeaders) {
3536
defaultHttpDataSourceFactory.setDefaultRequestProperties(httpHeaders);
3637
}
3738

39+
@NonNull
3840
@Override
3941
public DataSource createDataSource() {
4042
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(context).build();
4143

42-
defaultDatasourceFactory = new DefaultDataSource.Factory(this.context, defaultHttpDataSourceFactory);
44+
DefaultDataSource.Factory defaultDatasourceFactory = new DefaultDataSource.Factory(this.context, defaultHttpDataSourceFactory);
4345
defaultDatasourceFactory.setTransferListener(bandwidthMeter);
4446

4547
SimpleCache simpleCache = SimpleCacheSingleton.getInstance(context, maxCacheSize).simpleCache;

android/src/main/java/com/lazyarts/vikram/cached_video_player/CachedVideoPlayer.java

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.android.exoplayer2.Format;
1919
import com.google.android.exoplayer2.MediaItem;
2020
import com.google.android.exoplayer2.PlaybackException;
21-
import com.google.android.exoplayer2.PlaybackParameters;
2221
import com.google.android.exoplayer2.Player;
2322
import com.google.android.exoplayer2.audio.AudioAttributes;
2423
import com.google.android.exoplayer2.source.MediaSource;
@@ -47,7 +46,7 @@ final class CachedVideoPlayer {
4746
private static final String FORMAT_HLS = "hls";
4847
private static final String FORMAT_OTHER = "other";
4948

50-
private ExoPlayer exoPlayer;
49+
private final ExoPlayer exoPlayer;
5150

5251
private Surface surface;
5352

@@ -114,45 +113,32 @@ private MediaSource buildMediaSource(
114113
if (formatHint == null) {
115114
type = Util.inferContentType(uri.getLastPathSegment());
116115
} else {
117-
switch (formatHint) {
118-
case FORMAT_SS:
119-
type = C.TYPE_SS;
120-
break;
121-
case FORMAT_DASH:
122-
type = C.TYPE_DASH;
123-
break;
124-
case FORMAT_HLS:
125-
type = C.TYPE_HLS;
126-
break;
127-
case FORMAT_OTHER:
128-
type = C.TYPE_OTHER;
129-
break;
130-
default:
131-
type = -1;
132-
break;
133-
}
134-
}
135-
switch (type) {
136-
case C.TYPE_SS:
137-
return new SsMediaSource.Factory(
138-
new DefaultSsChunkSource.Factory(mediaDataSourceFactory),
139-
new DefaultDataSource.Factory(context, mediaDataSourceFactory))
140-
.createMediaSource(MediaItem.fromUri(uri));
141-
case C.TYPE_DASH:
142-
return new DashMediaSource.Factory(
143-
new DefaultDashChunkSource.Factory(mediaDataSourceFactory),
144-
new DefaultDataSource.Factory(context, mediaDataSourceFactory))
145-
.createMediaSource(MediaItem.fromUri(uri));
146-
case C.TYPE_HLS:
147-
return new HlsMediaSource.Factory(mediaDataSourceFactory)
148-
.createMediaSource(MediaItem.fromUri(uri));
149-
case C.TYPE_OTHER:
150-
return new ProgressiveMediaSource.Factory(mediaDataSourceFactory)
151-
.createMediaSource(MediaItem.fromUri(uri));
152-
default: {
153-
throw new IllegalStateException("Unsupported type: " + type);
154-
}
116+
type = switch (formatHint) {
117+
case FORMAT_SS -> C.TYPE_SS;
118+
case FORMAT_DASH -> C.TYPE_DASH;
119+
case FORMAT_HLS -> C.TYPE_HLS;
120+
case FORMAT_OTHER -> C.TYPE_OTHER;
121+
default -> -1;
122+
};
155123
}
124+
return switch (type) {
125+
case C.TYPE_SS -> new SsMediaSource.Factory(
126+
new DefaultSsChunkSource.Factory(mediaDataSourceFactory),
127+
new DefaultDataSource.Factory(context, mediaDataSourceFactory))
128+
.createMediaSource(MediaItem.fromUri(uri));
129+
case C.TYPE_DASH -> new DashMediaSource.Factory(
130+
new DefaultDashChunkSource.Factory(mediaDataSourceFactory),
131+
new DefaultDataSource.Factory(context, mediaDataSourceFactory))
132+
.createMediaSource(MediaItem.fromUri(uri));
133+
case C.TYPE_HLS ->
134+
new HlsMediaSource.Factory(mediaDataSourceFactory)
135+
.createMediaSource(MediaItem.fromUri(uri));
136+
case C.TYPE_OTHER ->
137+
new ProgressiveMediaSource.Factory(mediaDataSourceFactory)
138+
.createMediaSource(MediaItem.fromUri(uri));
139+
default ->
140+
throw new IllegalStateException("Unsupported type: " + type);
141+
};
156142
}
157143

158144
private void setupVideoPlayer(
@@ -212,9 +198,7 @@ public void onPlaybackStateChanged(final int playbackState) {
212198
@Override
213199
public void onPlayerError(@NonNull PlaybackException error) {
214200
setBuffering(false);
215-
if (eventSink != null) {
216-
eventSink.error("VideoError", "Video player had error " + error, null);
217-
}
201+
eventSink.error("VideoError", "Video player had error " + error, null);
218202
}
219203
});
220204
}
@@ -230,7 +214,7 @@ void sendBufferingUpdate() {
230214

231215
private static void setAudioAttributes(ExoPlayer exoPlayer, boolean isMixMode) {
232216
exoPlayer.setAudioAttributes(
233-
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build(), !isMixMode);
217+
new AudioAttributes.Builder().setContentType(com.google.android.exoplayer2.C.AUDIO_CONTENT_TYPE_MOVIE).build(), !isMixMode);
234218
}
235219

236220
void play() {
@@ -253,9 +237,7 @@ void setVolume(double value) {
253237
void setPlaybackSpeed(double value) {
254238
// We do not need to consider pitch and skipSilence for now as we do not handle them and
255239
// therefore never diverge from the default values.
256-
final PlaybackParameters playbackParameters = new PlaybackParameters(((float) value));
257-
258-
exoPlayer.setPlaybackParameters(playbackParameters);
240+
exoPlayer.setPlaybackSpeed((float) value);
259241
}
260242

261243
void seekTo(int location) {

android/src/main/java/com/lazyarts/vikram/cached_video_player/CachedVideoPlayerPlugin.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import android.content.Context;
88
import android.os.Build;
99
import android.util.LongSparseArray;
10+
11+
import androidx.annotation.NonNull;
12+
1013
import io.flutter.FlutterInjector;
1114
import io.flutter.Log;
1215
import io.flutter.embedding.engine.plugins.FlutterPlugin;
@@ -31,7 +34,7 @@ public class CachedVideoPlayerPlugin implements FlutterPlugin, VideoPlayerApi {
3134
private static final String TAG = "VideoPlayerPlugin";
3235
private final LongSparseArray<CachedVideoPlayer> videoPlayers = new LongSparseArray<>();
3336
private FlutterState flutterState;
34-
private VideoPlayerOptions options = new VideoPlayerOptions();
37+
private final VideoPlayerOptions options = new VideoPlayerOptions();
3538

3639
/** Register this with the v2 embedding for the plugin to respond to lifecycle callbacks. */
3740
public CachedVideoPlayerPlugin() {}
@@ -62,20 +65,7 @@ public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registra
6265
@Override
6366
public void onAttachedToEngine(FlutterPluginBinding binding) {
6467

65-
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
66-
try {
67-
HttpsURLConnection.setDefaultSSLSocketFactory(new CustomSSLSocketFactory());
68-
} catch (KeyManagementException | NoSuchAlgorithmException e) {
69-
Log.w(
70-
TAG,
71-
"Failed to enable TLSv1.1 and TLSv1.2 Protocols for API level 19 and below.\n"
72-
+ "For more information about Socket Security, please consult the following link:\n"
73-
+ "https://developer.android.com/reference/javax/net/ssl/SSLSocket",
74-
e);
75-
}
76-
}
77-
78-
final FlutterInjector injector = FlutterInjector.instance();
68+
final FlutterInjector injector = FlutterInjector.instance();
7969
this.flutterState =
8070
new FlutterState(
8171
binding.getApplicationContext(),
@@ -87,7 +77,7 @@ public void onAttachedToEngine(FlutterPluginBinding binding) {
8777
}
8878

8979
@Override
90-
public void onDetachedFromEngine(FlutterPluginBinding binding) {
80+
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
9181
if (flutterState == null) {
9282
Log.wtf(TAG, "Detached from the engine before registering to it.");
9383
}
@@ -142,7 +132,6 @@ public TextureMessage create(CreateMessage arg) {
142132
null,
143133
options);
144134
} else {
145-
@SuppressWarnings("unchecked")
146135
Map<String, String> httpHeaders = arg.getHttpHeaders();
147136
player =
148137
new CachedVideoPlayer(

android/src/main/java/com/lazyarts/vikram/cached_video_player/CustomSSLSocketFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import javax.net.ssl.SSLSocketFactory;
1515

1616
public class CustomSSLSocketFactory extends SSLSocketFactory {
17-
private SSLSocketFactory sslSocketFactory;
17+
private final SSLSocketFactory sslSocketFactory;
1818

1919
public CustomSSLSocketFactory() throws KeyManagementException, NoSuchAlgorithmException {
2020
SSLContext context = SSLContext.getInstance("TLS");

0 commit comments

Comments
 (0)