Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -419,16 +419,22 @@ public void setFormatHint(@Nullable String setterArg) {
this.formatHint = setterArg;
}

private @Nullable Map<String, String> httpHeaders;
private @NonNull Map<String, String> httpHeaders;

public @Nullable Map<String, String> getHttpHeaders() {
public @NonNull Map<String, String> getHttpHeaders() {
return httpHeaders;
}

public void setHttpHeaders(@Nullable Map<String, String> setterArg) {
public void setHttpHeaders(@NonNull Map<String, String> setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"httpHeaders\" is null.");
}
this.httpHeaders = setterArg;
}

/** Constructor is private to enforce null safety; use Builder. */
private CreateMessage() {}

public static class Builder {
private @Nullable String asset;

Expand Down Expand Up @@ -460,7 +466,7 @@ public static class Builder {

private @Nullable Map<String, String> httpHeaders;

public @NonNull Builder setHttpHeaders(@Nullable Map<String, String> setterArg) {
public @NonNull Builder setHttpHeaders(@NonNull Map<String, String> setterArg) {
this.httpHeaders = setterArg;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Context;
import android.net.Uri;
import android.view.Surface;
import androidx.annotation.NonNull;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
Expand Down Expand Up @@ -64,7 +65,7 @@ final class VideoPlayer {
TextureRegistry.SurfaceTextureEntry textureEntry,
String dataSource,
String formatHint,
Map<String, String> httpHeaders,
@NonNull Map<String, String> httpHeaders,
VideoPlayerOptions options) {
this.eventChannel = eventChannel;
this.textureEntry = textureEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,35 @@ class AndroidVideoPlayer extends VideoPlayerPlatform {

@override
Future<int?> create(DataSource dataSource) async {
final CreateMessage message = CreateMessage();

String? asset;
String? packageName;
String? uri;
String? formatHint;
Map<String, String> httpHeaders = <String, String>{};
switch (dataSource.sourceType) {
case DataSourceType.asset:
message.asset = dataSource.asset;
message.packageName = dataSource.package;
asset = dataSource.asset;
packageName = dataSource.package;
break;
case DataSourceType.network:
message.uri = dataSource.uri;
message.formatHint = _videoFormatStringMap[dataSource.formatHint];
message.httpHeaders = dataSource.httpHeaders;
uri = dataSource.uri;
formatHint = _videoFormatStringMap[dataSource.formatHint];
httpHeaders = dataSource.httpHeaders;
break;
case DataSourceType.file:
message.uri = dataSource.uri;
uri = dataSource.uri;
break;
case DataSourceType.contentUri:
message.uri = dataSource.uri;
uri = dataSource.uri;
break;
}
final CreateMessage message = CreateMessage(
asset: asset,
packageName: packageName,
uri: uri,
httpHeaders: httpHeaders,
formatHint: formatHint,
);

final TextureMessage response = await _api.create(message);
return response.textureId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ class CreateMessage {
this.uri,
this.packageName,
this.formatHint,
this.httpHeaders,
required this.httpHeaders,
});

String? asset;
String? uri;
String? packageName;
String? formatHint;
Map<String?, String?>? httpHeaders;
Map<String?, String?> httpHeaders;

Object encode() {
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
Expand All @@ -164,8 +164,8 @@ class CreateMessage {
uri: pigeonMap['uri'] as String?,
packageName: pigeonMap['packageName'] as String?,
formatHint: pigeonMap['formatHint'] as String?,
httpHeaders: (pigeonMap['httpHeaders'] as Map<Object?, Object?>?)
?.cast<String?, String?>(),
httpHeaders: (pigeonMap['httpHeaders'] as Map<Object?, Object?>?)!
.cast<String?, String?>(),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ class PositionMessage {
}

class CreateMessage {
CreateMessage({required this.httpHeaders});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this required, rather than defaulting to an empty collection?

Copy link
Member Author

Choose a reason for hiding this comment

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

Pigeon demands there be no logic here, it doesn't generate code for initialization.

Copy link
Contributor

Choose a reason for hiding this comment

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

String? asset;
String? uri;
String? packageName;
String? formatHint;
Map<String?, String?>? httpHeaders;
Map<String?, String?> httpHeaders;
}

class MixWithOthersMessage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ @interface FLTVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
@property(nonatomic, readonly) BOOL isInitialized;
- (instancetype)initWithURL:(NSURL *)url
frameUpdater:(FLTFrameUpdater *)frameUpdater
httpHeaders:(NSDictionary<NSString *, NSString *> *)headers;
httpHeaders:(nonnull NSDictionary<NSString *, NSString *> *)headers;
@end

static void *timeRangeContext = &timeRangeContext;
Expand All @@ -57,7 +57,7 @@ - (instancetype)initWithURL:(NSURL *)url
@implementation FLTVideoPlayer
- (instancetype)initWithAsset:(NSString *)asset frameUpdater:(FLTFrameUpdater *)frameUpdater {
NSString *path = [[NSBundle mainBundle] pathForResource:asset ofType:nil];
return [self initWithURL:[NSURL fileURLWithPath:path] frameUpdater:frameUpdater httpHeaders:nil];
return [self initWithURL:[NSURL fileURLWithPath:path] frameUpdater:frameUpdater httpHeaders:@{}];
}

- (void)addObservers:(AVPlayerItem *)item {
Expand Down Expand Up @@ -177,7 +177,7 @@ - (void)createVideoOutputAndDisplayLink:(FLTFrameUpdater *)frameUpdater {

- (instancetype)initWithURL:(NSURL *)url
frameUpdater:(FLTFrameUpdater *)frameUpdater
httpHeaders:(NSDictionary<NSString *, NSString *> *)headers {
httpHeaders:(nonnull NSDictionary<NSString *, NSString *> *)headers {
NSDictionary<NSString *, id> *options = nil;
if (headers != nil && [headers count] != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The headers != nil can be removed.

(Technically it could have been removed either way since [nil count] is zero, but it should definitely be removed now.)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

options = @{@"AVURLAssetHTTPHeaderFieldsKey" : headers};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,18 @@ NS_ASSUME_NONNULL_BEGIN
@end

@interface FLTCreateMessage : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithAsset:(nullable NSString *)asset
uri:(nullable NSString *)uri
packageName:(nullable NSString *)packageName
formatHint:(nullable NSString *)formatHint
httpHeaders:(nullable NSDictionary<NSString *, NSString *> *)httpHeaders;
httpHeaders:(NSDictionary<NSString *, NSString *> *)httpHeaders;
@property(nonatomic, copy, nullable) NSString *asset;
@property(nonatomic, copy, nullable) NSString *uri;
@property(nonatomic, copy, nullable) NSString *packageName;
@property(nonatomic, copy, nullable) NSString *formatHint;
@property(nonatomic, strong, nullable) NSDictionary<NSString *, NSString *> *httpHeaders;
@property(nonatomic, strong) NSDictionary<NSString *, NSString *> *httpHeaders;
@end

@interface FLTMixWithOthersMessage : NSObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ + (instancetype)makeWithAsset:(nullable NSString *)asset
uri:(nullable NSString *)uri
packageName:(nullable NSString *)packageName
formatHint:(nullable NSString *)formatHint
httpHeaders:(nullable NSDictionary<NSString *, NSString *> *)httpHeaders {
httpHeaders:(NSDictionary<NSString *, NSString *> *)httpHeaders {
FLTCreateMessage *pigeonResult = [[FLTCreateMessage alloc] init];
pigeonResult.asset = asset;
pigeonResult.uri = uri;
Expand All @@ -188,6 +188,7 @@ + (FLTCreateMessage *)fromMap:(NSDictionary *)dict {
pigeonResult.packageName = GetNullableObject(dict, @"packageName");
pigeonResult.formatHint = GetNullableObject(dict, @"formatHint");
pigeonResult.httpHeaders = GetNullableObject(dict, @"httpHeaders");
NSAssert(pigeonResult.httpHeaders != nil, @"");
return pigeonResult;
}
- (NSDictionary *)toMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,35 @@ class AVFoundationVideoPlayer extends VideoPlayerPlatform {

@override
Future<int?> create(DataSource dataSource) async {
final CreateMessage message = CreateMessage();

String? asset;
String? packageName;
String? uri;
String? formatHint;
Map<String, String> httpHeaders = <String, String>{};
switch (dataSource.sourceType) {
case DataSourceType.asset:
message.asset = dataSource.asset;
message.packageName = dataSource.package;
asset = dataSource.asset;
packageName = dataSource.package;
break;
case DataSourceType.network:
message.uri = dataSource.uri;
message.formatHint = _videoFormatStringMap[dataSource.formatHint];
message.httpHeaders = dataSource.httpHeaders;
uri = dataSource.uri;
formatHint = _videoFormatStringMap[dataSource.formatHint];
httpHeaders = dataSource.httpHeaders;
break;
case DataSourceType.file:
message.uri = dataSource.uri;
uri = dataSource.uri;
break;
case DataSourceType.contentUri:
message.uri = dataSource.uri;
uri = dataSource.uri;
break;
}
final CreateMessage message = CreateMessage(
asset: asset,
packageName: packageName,
uri: uri,
httpHeaders: httpHeaders,
formatHint: formatHint,
);

final TextureMessage response = await _api.create(message);
return response.textureId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ class CreateMessage {
this.uri,
this.packageName,
this.formatHint,
this.httpHeaders,
required this.httpHeaders,
});

String? asset;
String? uri;
String? packageName;
String? formatHint;
Map<String?, String?>? httpHeaders;
Map<String?, String?> httpHeaders;

Object encode() {
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
Expand All @@ -164,8 +164,8 @@ class CreateMessage {
uri: pigeonMap['uri'] as String?,
packageName: pigeonMap['packageName'] as String?,
formatHint: pigeonMap['formatHint'] as String?,
httpHeaders: (pigeonMap['httpHeaders'] as Map<Object?, Object?>?)
?.cast<String?, String?>(),
httpHeaders: (pigeonMap['httpHeaders'] as Map<Object?, Object?>?)!
.cast<String?, String?>(),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ class PositionMessage {
}

class CreateMessage {
CreateMessage({required this.httpHeaders});
String? asset;
String? uri;
String? packageName;
String? formatHint;
Map<String?, String?>? httpHeaders;
Map<String?, String?> httpHeaders;
}

class MixWithOthersMessage {
Expand Down