Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[video_player] Caching for network data source #2429

Closed
wants to merge 128 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
76d56ca
Adds support for holes in polygon overlays to the Google Maps plugin
sanekyy Jun 10, 2019
8826721
Add name and contact info to the AUTHORS file
sanekyy Jun 10, 2019
9252dc4
fix holes generating in example
sanekyy Jun 17, 2019
a4eeab5
Merge branch 'master' into polygon_holes
sanekyy Jun 17, 2019
1b26908
merge with upstream/master
sanekyy Jun 17, 2019
01bd55c
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jun 20, 2019
69d3889
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jun 20, 2019
18137c2
change version to 0.5.19
sanekyy Jun 20, 2019
a86e25f
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jun 21, 2019
e866736
change version to 0.5.20
sanekyy Jun 21, 2019
0d404b4
Merge remote-tracking branch 'upstream/master' into polygon_holes
sanekyy Jun 25, 2019
32ee443
fix format
sanekyy Jun 27, 2019
71c45b5
Merge remote-tracking branch 'upstream/master'
sanekyy Jun 27, 2019
4f24a58
Merge branch 'polygon_holes'
sanekyy Jun 27, 2019
5233c0d
fix format
sanekyy Jun 27, 2019
a952a34
Merge remote-tracking branch 'upstream/master'
sanekyy Jul 5, 2019
1faf0d4
Merge branch 'master' into polygon_holes
sanekyy Jul 5, 2019
b4ae7bf
Merge remote-tracking branch 'upstream/master'
sanekyy Jul 11, 2019
49d08b3
Merge branch 'master' into polygon_holes
sanekyy Jul 11, 2019
b526132
Merge remote-tracking branch 'upstream/master'
sanekyy Jul 20, 2019
2d55631
Merge branch 'master' into polygon_holes
sanekyy Jul 20, 2019
7871f33
Merge remote-tracking branch 'upstream/master'
sanekyy Jul 26, 2019
185f67b
Merge branch 'master' into polygon_holes
sanekyy Jul 26, 2019
14136d5
Merge remote-tracking branch 'upstream/master'
sanekyy Sep 4, 2019
4283ce0
Merge branch 'master' into polygon_holes
sanekyy Sep 4, 2019
af1c9b0
add additional documentation about what is a hole
sanekyy Sep 4, 2019
242aa87
migrate to Maps SDK v3
sanekyy Sep 5, 2019
9255eac
add missed maps sdk aar
sanekyy Sep 5, 2019
670f24a
remove unnecessary maps-sdk .arr from android/libs and add to example…
sanekyy Sep 6, 2019
93535a0
add maps sdk v3 back
sanekyy Sep 6, 2019
c12ad1d
Revert "add maps sdk v3 back"
sanekyy Sep 6, 2019
d5fda58
Revert "remove unnecessary maps-sdk .arr from android/libs and add to…
sanekyy Sep 6, 2019
fc21131
Tile overlays
otopba Sep 8, 2019
1289d4f
handle null tile
otopba Sep 10, 2019
edb0456
Add worker class
otopba Sep 10, 2019
8edbf83
Merge branch 'tile_overlays'
sanekyy Sep 10, 2019
0ee16bf
Merge branch 'google_maps_v3'
sanekyy Sep 10, 2019
6eb491e
fix
otopba Sep 10, 2019
47a7d67
handle initial state
otopba Sep 11, 2019
fa9b814
Merge branch 'tile_overlays'
otopba Sep 11, 2019
f3af72a
fix initial state
otopba Sep 11, 2019
4ff7ebb
Merge branch 'tile_overlays'
otopba Sep 11, 2019
9c0bcfc
updateInitialTileOverlays
otopba Sep 11, 2019
94a9131
updateInitialTileOverlays
otopba Sep 15, 2019
b1812a3
add clearTileCache method
otopba Sep 16, 2019
085385d
Merge pull request #1 from sanekyy/tile_overlays
otopba Sep 17, 2019
0dd67f7
[video_player] Add caching on Android
999eagle Sep 4, 2019
042037b
[video_player] Make caching configurable
999eagle Sep 6, 2019
fa0d54c
[video_player] Add video caching on iOS
999eagle Sep 7, 2019
262ca38
[video_player] Change cache arguments to int
999eagle Sep 9, 2019
1c45896
[video_player] Use static resource loader for caching
999eagle Sep 9, 2019
0eeb002
ios escape alphanumeric characters
lukepighetti Sep 22, 2019
33f0090
fix file loading on iOS, expose cache size arguments
lukepighetti Sep 25, 2019
fa96eab
comments
lukepighetti Sep 25, 2019
6da01a8
[untested] static method to set cache once
lukepighetti Sep 30, 2019
8b23e1b
remove unused constructor args, add asserts
lukepighetti Oct 1, 2019
e49ead2
Fix formatting
999eagle Oct 1, 2019
90c229f
Add myself to AUTHORS
999eagle Oct 1, 2019
5f4f141
Update version and changelog
999eagle Oct 1, 2019
96d4ede
Merge remote-tracking branch 'upstream/master'
sanekyy Dec 5, 2019
27b258c
Merge remote-tracking branch 'upstream/master'
sanekyy Dec 6, 2019
5d2ee61
revert google_maps_v3
sanekyy Dec 10, 2019
b3bf399
revert tile overlays
sanekyy Dec 10, 2019
4bb5b37
revert to origin master
sanekyy Dec 10, 2019
c81b666
test commit
sanekyy Dec 10, 2019
010ea2b
Revert "test commit"
sanekyy Dec 10, 2019
d736a96
fix merge conflicts
sanekyy Dec 10, 2019
7db7db3
Merge remote-tracking branch 'upstream/master'
sanekyy Dec 10, 2019
c0aa086
Merge remote-tracking branch 'upstream/master'
sanekyy Dec 12, 2019
70ef4bb
Merge remote-tracking branch 'upstream/master'
otopba Dec 12, 2019
41749fb
Fix blinking
otopba Dec 14, 2019
0842159
Revert "Fix blinking"
otopba Dec 14, 2019
6452e0d
merge upstream with caching feature from 999eagle fork
sanekyy Dec 15, 2019
5b8c45d
fix documentation
sanekyy Dec 15, 2019
dfcf6e8
improve caching logic
sanekyy Dec 17, 2019
b2c8687
iOS support
otopba Dec 17, 2019
9b93d68
rename maxFileSize -> maxCacheFileSize
otopba Dec 17, 2019
7727ade
Read useCache only if have uriArg
otopba Dec 17, 2019
cdd0ebf
[shared_preferences] add a no-op android folder to web/macos packages…
amirh Dec 12, 2019
46b9858
Remove AndroidX references from no-op android implementations (#2411)
amirh Dec 12, 2019
6d6815e
[sensors]Cancel sensors example timer avoid exception (#2375)
figureConan Dec 12, 2019
c933bad
[e2e] Creates basic support/documentation/example to iOS. (#2394)
AlbertWang0116 Dec 12, 2019
cb87553
[shared_preferences web/macos] remove unused onMethodCall methods (#2…
amirh Dec 12, 2019
afe8b0e
[webview_flutter] add gesture navigation for iOS (#2339)
wwwdata Dec 13, 2019
71cb85d
Update endorsed macos plugins readme and update others (#2407)
franciscojma86 Dec 13, 2019
2ae83bb
[plugin_platform_interface] Don't use const Object as a token (#2417)
amirh Dec 13, 2019
b41574a
[url_launcher_platform_interface] use non static token for platform i…
amirh Dec 13, 2019
ed43957
[ios_platform_images] Made ios_platform_images set the correct image …
gaaclarke Dec 13, 2019
0f392ac
[google_sign_in] Pass the client id to the platform interface. (#2427)
chingjun Dec 17, 2019
99a7b9b
[in_app_purchase]Change a comment. (#2329)
HiIamAlanOu Dec 17, 2019
6bf582b
re-enable stable CI (#2402)
amirh Dec 17, 2019
5ee6a24
[flutter_webview] Raise min Flutter SDK to stable (#2425)
Dec 18, 2019
2b2ecec
[battery] cleanup for Android embedding post 1.12 (#2400)
xster Dec 18, 2019
3961bca
[google_sign_in] Expose network error (#2398)
yuwen-yan Dec 19, 2019
e44e6f5
[ios_platform_images] Removed android support from the pubspec. (#2432)
gaaclarke Dec 19, 2019
13c796c
[google_sign_in]Update google_sign_in_example name in pubspec.yaml (#…
figureConan Dec 19, 2019
47b6fd3
Merge remote-tracking branch 'upstream/master'
sanekyy Dec 23, 2019
e007126
Merge remote-tracking branch 'upstream/master'
sanekyy Jan 8, 2020
96b4f7a
Merge remote-tracking branch 'upstream/master'
sanekyy Jan 14, 2020
a5bc3d5
Merge branch 'master' into caching
sanekyy Jan 14, 2020
dead810
Merge remote-tracking branch 'origin/caching' into caching
sanekyy Jan 14, 2020
4aeb7a8
Merge remote-tracking branch 'upstream/master'
sanekyy Jan 19, 2020
1774f26
Merge branch 'master' into caching
sanekyy Jan 19, 2020
b374825
workaround for success build checks in PR
sanekyy Jan 19, 2020
ed657d6
bump video_player_web version
sanekyy Jan 19, 2020
c920b58
Merge remote-tracking branch 'upstream/master' into caching
sanekyy Feb 1, 2020
9c5810c
merge fixes
sanekyy Feb 1, 2020
4e8c909
Merge remote-tracking branch 'upstream/master' into caching
sanekyy Feb 17, 2020
bd2c825
merge upstream
sanekyy Feb 17, 2020
d90473d
Merge remote-tracking branch 'upstream/master' into caching
sanekyy Feb 26, 2020
b3e94e7
fix merge issues
sanekyy Feb 26, 2020
1e30a50
fix version and format
sanekyy Feb 27, 2020
8f86154
fix version
sanekyy Feb 27, 2020
130a847
Merge remote-tracking branch 'upstream/master' into caching
sanekyy Mar 18, 2020
24e3b20
Merge remote-tracking branch 'upstream/master' into caching
sanekyy Mar 31, 2020
3b800a7
Merge branch 'master' into caching
otopba May 1, 2020
740cb3e
merge
otopba May 1, 2020
e33cffc
fix video_player_platform_interface version
otopba May 1, 2020
5ac10c1
Merge branch 'upstream-master' into caching
sanekyy Oct 10, 2020
c1e2c2a
fetch upstream
sanekyy Oct 10, 2020
a9ca995
fix iOS issueses
sanekyy Oct 10, 2020
16e9c54
revert dependencies issues
sanekyy Oct 10, 2020
0a1f3c4
fix tests
sanekyy Oct 10, 2020
5f16b27
apply format
sanekyy Oct 10, 2020
1fc4b5c
fix tests
sanekyy Oct 10, 2020
ebfc32a
Merge branch 'master' into caching
otopba Oct 18, 2020
77bc64b
Format code
otopba Oct 18, 2020
b38cc87
Fix number to long convert
otopba Oct 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ Kazuki Yamaguchi <[email protected]>
Eitan Schwartz <[email protected]>
Chris Rutkowski <[email protected]>
Juan Alvarez <[email protected]>
Aleksandr Yurkovskiy <[email protected]>
Iurii Dorofeev <[email protected]>
5 changes: 4 additions & 1 deletion packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.12.0

* Add caching functionality to videos from network sources.

## 0.11.1+2

* Update android compileSdkVersion to 29.
Expand Down Expand Up @@ -85,7 +89,6 @@
* Added support for cleaning up the plugin if used for add-to-app (Flutter
v1.15.3 is required for that feature).


## 0.10.7

* `VideoPlayerController` support for reading closed caption files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,53 @@
@SuppressWarnings("unused")
public class Messages {

/** Generated class from Pigeon that represents data sent in messages. */
public static class InitializeMessage {
private Long maxCacheSize;

public Long getMaxCacheSize() {
return maxCacheSize;
}

public void setMaxCacheSize(Long setterArg) {
this.maxCacheSize = setterArg;
}

private Long maxCacheFileSize;

public Long getMaxCacheFileSize() {
return maxCacheFileSize;
}

public void setMaxCacheFileSize(Long setterArg) {
this.maxCacheFileSize = setterArg;
}

HashMap toMap() {
HashMap<String, Object> toMapResult = new HashMap<>();
toMapResult.put("maxCacheSize", maxCacheSize);
toMapResult.put("maxCacheFileSize", maxCacheFileSize);
return toMapResult;
}

static InitializeMessage fromMap(HashMap map) {
InitializeMessage fromMapResult = new InitializeMessage();
Object maxCacheSize = map.get("maxCacheSize");
fromMapResult.maxCacheSize =
(maxCacheSize == null)
? null
: ((maxCacheSize instanceof Integer) ? (Integer) maxCacheSize : (Long) maxCacheSize);
Object maxCacheFileSize = map.get("maxCacheFileSize");
fromMapResult.maxCacheFileSize =
(maxCacheFileSize == null)
? null
: ((maxCacheFileSize instanceof Integer)
? (Integer) maxCacheFileSize
: (Long) maxCacheFileSize);
return fromMapResult;
}
}

/** Generated class from Pigeon that represents data sent in messages. */
public static class TextureMessage {
private Long textureId;
Expand Down Expand Up @@ -83,12 +130,23 @@ public void setFormatHint(String setterArg) {
this.formatHint = setterArg;
}

private Boolean useCache;

public Boolean getUseCache() {
return useCache;
}

public void setUseCache(Boolean setterArg) {
this.useCache = setterArg;
}

HashMap toMap() {
HashMap<String, Object> toMapResult = new HashMap<>();
toMapResult.put("asset", asset);
toMapResult.put("uri", uri);
toMapResult.put("packageName", packageName);
toMapResult.put("formatHint", formatHint);
toMapResult.put("useCache", useCache);
return toMapResult;
}

Expand All @@ -102,6 +160,8 @@ static CreateMessage fromMap(HashMap map) {
fromMapResult.packageName = (String) packageName;
Object formatHint = map.get("formatHint");
fromMapResult.formatHint = (String) formatHint;
Object useCache = map.get("useCache");
fromMapResult.useCache = (Boolean) useCache;
return fromMapResult;
}
}
Expand Down Expand Up @@ -305,7 +365,7 @@ static MixWithOthersMessage fromMap(HashMap map) {

/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface VideoPlayerApi {
void initialize();
void initialize(InitializeMessage arg);

TextureMessage create(CreateMessage arg);

Expand Down Expand Up @@ -340,7 +400,9 @@ static void setup(BinaryMessenger binaryMessenger, VideoPlayerApi api) {
(message, reply) -> {
HashMap<String, HashMap> wrapped = new HashMap<>();
try {
api.initialize();
@SuppressWarnings("ConstantConditions")
InitializeMessage input = InitializeMessage.fromMap((HashMap) message);
api.initialize(input);
wrapped.put("result", null);
} catch (Exception exception) {
wrapped.put("error", wrapError(exception));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.FileDataSource;
import com.google.android.exoplayer2.upstream.cache.CacheDataSink;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.exoplayer2.util.Util;
import io.flutter.plugin.common.EventChannel;
import io.flutter.view.TextureRegistry;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -65,7 +72,10 @@ final class VideoPlayer {
TextureRegistry.SurfaceTextureEntry textureEntry,
String dataSource,
String formatHint,
VideoPlayerOptions options) {
VideoPlayerOptions options,
long maxCacheSize,
long maxCacheFileSize,
boolean useCache) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why have an extra parameter here instead of just setting this based on whether maxCacheSize and maxCacheFileSize > 0?

this.eventChannel = eventChannel;
this.textureEntry = textureEntry;
this.options = options;
Expand All @@ -84,6 +94,10 @@ final class VideoPlayer {
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
true);
if (useCache && maxCacheSize > 0 && maxCacheFileSize > 0) {
dataSourceFactory =
new CacheDataSourceFactory(context, maxCacheSize, maxCacheFileSize, dataSourceFactory);
}
} else {
dataSourceFactory = new DefaultDataSourceFactory(context, "ExoPlayer");
}
Expand Down Expand Up @@ -287,4 +301,42 @@ void dispose() {
exoPlayer.release();
}
}

static class CacheDataSourceFactory implements DataSource.Factory {
private final Context context;
private final DefaultDataSourceFactory defaultDatasourceFactory;
private final long maxFileSize, maxCacheSize;
private static SimpleCache downloadCache;

CacheDataSourceFactory(
Context context,
long maxCacheSize,
long maxFileSize,
DataSource.Factory upstreamDataSource) {
super();
this.context = context;
this.maxCacheSize = maxCacheSize;
this.maxFileSize = maxFileSize;
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
defaultDatasourceFactory =
new DefaultDataSourceFactory(this.context, bandwidthMeter, upstreamDataSource);
}

@Override
public DataSource createDataSource() {
LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(maxCacheSize);

if (downloadCache == null) {
downloadCache = new SimpleCache(new File(context.getCacheDir(), "video"), evictor);
}

return new CacheDataSource(
downloadCache,
defaultDatasourceFactory.createDataSource(),
new FileDataSource(),
new CacheDataSink(downloadCache, maxFileSize),
CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR,
null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugins.videoplayer.Messages.CreateMessage;
import io.flutter.plugins.videoplayer.Messages.InitializeMessage;
import io.flutter.plugins.videoplayer.Messages.LoopingMessage;
import io.flutter.plugins.videoplayer.Messages.MixWithOthersMessage;
import io.flutter.plugins.videoplayer.Messages.PlaybackSpeedMessage;
Expand All @@ -32,6 +33,9 @@ public class VideoPlayerPlugin implements FlutterPlugin, VideoPlayerApi {
private FlutterState flutterState;
private VideoPlayerOptions options = new VideoPlayerOptions();

private long maxCacheSize;
private long maxCacheFileSize;

/** Register this with the v2 embedding for the plugin to respond to lifecycle callbacks. */
public VideoPlayerPlugin() {}

Expand Down Expand Up @@ -110,8 +114,10 @@ private void onDestroy() {
disposeAllPlayers();
}

public void initialize() {
public void initialize(InitializeMessage arg) {
disposeAllPlayers();
maxCacheSize = arg.getMaxCacheSize();
maxCacheFileSize = arg.getMaxCacheFileSize();
}

public TextureMessage create(CreateMessage arg) {
Expand All @@ -137,7 +143,10 @@ public TextureMessage create(CreateMessage arg) {
handle,
"asset:///" + assetLookupKey,
null,
options);
options,
maxCacheSize,
maxCacheFileSize,
false);
videoPlayers.put(handle.id(), player);
} else {
player =
Expand All @@ -147,7 +156,10 @@ public TextureMessage create(CreateMessage arg) {
handle,
arg.getUri(),
arg.getFormatHint(),
options);
options,
maxCacheSize,
maxCacheFileSize,
arg.getUseCache());
videoPlayers.put(handle.id(), player);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/video_player/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

/// An example of using the plugin, controlling lifecycle and playback of the
/// video.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
Expand Down Expand Up @@ -221,6 +220,7 @@ class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
closedCaptionFile: _loadCaptions(),
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
useCache: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here - it seems like it's probably fine to opt users into caching as long as the max values are set and we document what they are/how to change them.

);

_controller.addListener(() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "FLTVideoPlayerPlugin.h"
#import <AVFoundation/AVFoundation.h>
#import <GLKit/GLKit.h>
#import "VIMediaCache.h"
#import "messages.h"

#if !__has_feature(objc_arc)
Expand Down Expand Up @@ -51,6 +52,7 @@ - (void)play;
- (void)pause;
- (void)setIsLooping:(bool)isLooping;
- (void)updatePlayingState;
+ (VIResourceLoaderManager*)resourceLoaderManager;
@end

static void* timeRangeContext = &timeRangeContext;
Expand Down Expand Up @@ -163,10 +165,29 @@ - (void)createVideoOutputAndDisplayLink:(FLTFrameUpdater*)frameUpdater {
}

- (instancetype)initWithURL:(NSURL*)url frameUpdater:(FLTFrameUpdater*)frameUpdater {
AVPlayerItem* item = [AVPlayerItem playerItemWithURL:url];
return [self initWithURL:url frameUpdater:frameUpdater enableCache:NO];
}

- (instancetype)initWithURL:(NSURL*)url
frameUpdater:(FLTFrameUpdater*)frameUpdater
enableCache:(BOOL)enableCache {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

AVPlayerItem* item;
if (enableCache) {
item = [[FLTVideoPlayer resourceLoaderManager] playerItemWithURL:url];
} else {
item = [AVPlayerItem playerItemWithURL:url];
}
return [self initWithPlayerItem:item frameUpdater:frameUpdater];
}

+ (VIResourceLoaderManager*)resourceLoaderManager {
static VIResourceLoaderManager* resourceLoaderManager = nil;
if (resourceLoaderManager == nil) {
resourceLoaderManager = [VIResourceLoaderManager new];
}
return resourceLoaderManager;
}

- (CGAffineTransform)fixTransform:(AVAssetTrack*)videoTrack {
CGAffineTransform transform = videoTrack.preferredTransform;
// TODO(@recastrodiaz): why do we need to do this? Why is the preferredTransform incorrect?
Expand Down Expand Up @@ -450,6 +471,8 @@ @interface FLTVideoPlayerPlugin () <FLTVideoPlayerApi>
@property(readonly, weak, nonatomic) NSObject<FlutterBinaryMessenger>* messenger;
@property(readonly, strong, nonatomic) NSMutableDictionary* players;
@property(readonly, strong, nonatomic) NSObject<FlutterPluginRegistrar>* registrar;
@property(readonly, nonatomic) long maxCacheSize;
@property(readonly, nonatomic) long maxCacheFileSize;
@end

@implementation FLTVideoPlayerPlugin
Expand Down Expand Up @@ -497,7 +520,7 @@ - (FLTTextureMessage*)onPlayerSetup:(FLTVideoPlayer*)player
return result;
}

- (void)initialize:(FlutterError* __autoreleasing*)error {
- (void)initialize:(FLTInitializeMessage*)input error:(FlutterError**)error {
// Allow audio playback when the Ring/Silent switch is set to silent
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

Expand All @@ -506,6 +529,8 @@ - (void)initialize:(FlutterError* __autoreleasing*)error {
[_players[textureId] dispose];
}
[_players removeAllObjects];
_maxCacheSize = [input.maxCacheSize longValue];
_maxCacheFileSize = [input.maxCacheFileSize longValue];
}

- (FLTTextureMessage*)create:(FLTCreateMessage*)input error:(FlutterError**)error {
Expand All @@ -521,8 +546,20 @@ - (FLTTextureMessage*)create:(FLTCreateMessage*)input error:(FlutterError**)erro
player = [[FLTVideoPlayer alloc] initWithAsset:assetPath frameUpdater:frameUpdater];
return [self onPlayerSetup:player frameUpdater:frameUpdater];
} else if (input.uri) {
player = [[FLTVideoPlayer alloc] initWithURL:[NSURL URLWithString:input.uri]
frameUpdater:frameUpdater];
BOOL useCache = input.useCache;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

BOOL enableCache = _maxCacheSize > 0 && _maxCacheFileSize > 0 && useCache;
if (enableCache) {
NSString* escapedURL = [input.uri
stringByAddingPercentEncodingWithAllowedCharacters:NSMutableCharacterSet
.alphanumericCharacterSet];

player = [[FLTVideoPlayer alloc] initWithURL:[NSURL URLWithString:escapedURL]
frameUpdater:frameUpdater
enableCache:enableCache];
} else {
player = [[FLTVideoPlayer alloc] initWithURL:[NSURL URLWithString:input.uri]
frameUpdater:frameUpdater];
}
return [self onPlayerSetup:player frameUpdater:frameUpdater];
} else {
*error = [FlutterError errorWithCode:@"video_player" message:@"not implemented" details:nil];
Expand Down
Loading