Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Added IOS buffer configuration to player #1230

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 ios/Classes/BetterPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly) bool isPlaying;
@property(nonatomic) bool isLooping;
@property(nonatomic, readonly) bool isInitialized;
@property(nonatomic, readonly) NSTimeInterval bufferDuration;
@property(nonatomic, readonly) NSString* key;
@property(nonatomic, readonly) int failedCount;
@property(nonatomic) AVPlayerLayer* _playerLayer;
Expand All @@ -38,6 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)play;
- (void)pause;
- (void)setIsLooping:(bool)isLooping;
- (void)setBufferDuration:(NSTimeInterval)bufferDuration;
- (void)updatePlayingState;
- (int64_t) duration;
- (int64_t) position;
Expand Down
9 changes: 9 additions & 0 deletions ios/Classes/BetterPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
_player.automaticallyWaitsToMinimizeStalling = false;
}
self._observersAdded = false;
_bufferDuration = 0;
return self;
}

Expand Down Expand Up @@ -228,6 +229,10 @@ - (void)setDataSourceURL:(NSURL*)url withKey:(NSString*)key withCertificateUrl:(
if (@available(iOS 10.0, *) && overriddenDuration > 0) {
_overriddenDuration = overriddenDuration;
}

if (@available(iOS 10.0, *)) {
[item setPreferredForwardBufferDuration:_bufferDuration];
}
return [self setDataSourcePlayerItem:item withKey:key];
}

Expand Down Expand Up @@ -539,6 +544,10 @@ - (void)setIsLooping:(bool)isLooping {
_isLooping = isLooping;
}

- (void)setBufferDuration:(NSTimeInterval)bufferDuration {
_bufferDuration = bufferDuration;
}

- (void)setVolume:(double)volume {
_player.volume = (float)((volume < 0.0) ? 0.0 : ((volume > 1.0) ? 1.0 : volume));
}
Expand Down
8 changes: 8 additions & 0 deletions ios/Classes/BetterPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
result(nil);
} else if ([@"create" isEqualToString:call.method]) {
BetterPlayer* player = [[BetterPlayer alloc] initWithFrame:CGRectZero];
NSDictionary *argsMap = call.arguments;

if ([argsMap objectForKey:@"maxBufferMs"] != [NSNull null]){
NSNumber *parseNumber = argsMap[@"maxBufferMs"];
float maxBufferMs = [parseNumber floatValue] / 1000;
[player setBufferDuration:maxBufferMs];
}

[self onPlayerSetup:player result:result];
} else {
NSDictionary* argsMap = call.arguments;
Expand Down
Loading