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

[video_player_avplay] Add setDisplayMode and setDisplayRotate API #789

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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 packages/video_player_avplay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 0.5.9

* Fix dash player fail to seek issue.
* Add setDisplayRotate API
* Add setDisplayMode API

## 0.5.8

Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_avplay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To use this package, add `video_player_avplay` as a dependency in your `pubspec.

```yaml
dependencies:
video_player_avplay: ^0.5.8
video_player_avplay: ^0.5.9
```

Then you can import `video_player_avplay` in your Dart code:
Expand Down
168 changes: 143 additions & 25 deletions packages/video_player_avplay/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,58 @@ class BufferConfigMessage {
}
}

class RotationMessage {
RotationMessage({
required this.playerId,
required this.rotation,
});

int playerId;

int rotation;

Object encode() {
return <Object?>[
playerId,
rotation,
];
}

static RotationMessage decode(Object result) {
result as List<Object?>;
return RotationMessage(
playerId: result[0]! as int,
rotation: result[1]! as int,
);
}
}

class DisplayModeMessage {
DisplayModeMessage({
required this.playerId,
required this.displayMode,
});

int playerId;

int displayMode;

Object encode() {
return <Object?>[
playerId,
displayMode,
];
}

static DisplayModeMessage decode(Object result) {
result as List<Object?>;
return DisplayModeMessage(
playerId: result[0]! as int,
displayMode: result[1]! as int,
);
}
}

class _VideoPlayerAvplayApiCodec extends StandardMessageCodec {
const _VideoPlayerAvplayApiCodec();
@override
Expand All @@ -462,45 +514,51 @@ class _VideoPlayerAvplayApiCodec extends StandardMessageCodec {
} else if (value is CreateMessage) {
buffer.putUint8(129);
writeValue(buffer, value.encode());
} else if (value is DurationMessage) {
} else if (value is DisplayModeMessage) {
buffer.putUint8(130);
writeValue(buffer, value.encode());
} else if (value is GeometryMessage) {
} else if (value is DurationMessage) {
buffer.putUint8(131);
writeValue(buffer, value.encode());
} else if (value is LoopingMessage) {
} else if (value is GeometryMessage) {
buffer.putUint8(132);
writeValue(buffer, value.encode());
} else if (value is MixWithOthersMessage) {
} else if (value is LoopingMessage) {
buffer.putUint8(133);
writeValue(buffer, value.encode());
} else if (value is PlaybackSpeedMessage) {
} else if (value is MixWithOthersMessage) {
buffer.putUint8(134);
writeValue(buffer, value.encode());
} else if (value is PlayerMessage) {
} else if (value is PlaybackSpeedMessage) {
buffer.putUint8(135);
writeValue(buffer, value.encode());
} else if (value is PositionMessage) {
} else if (value is PlayerMessage) {
buffer.putUint8(136);
writeValue(buffer, value.encode());
} else if (value is SelectedTracksMessage) {
} else if (value is PositionMessage) {
buffer.putUint8(137);
writeValue(buffer, value.encode());
} else if (value is StreamingPropertyMessage) {
} else if (value is RotationMessage) {
buffer.putUint8(138);
writeValue(buffer, value.encode());
} else if (value is StreamingPropertyTypeMessage) {
} else if (value is SelectedTracksMessage) {
buffer.putUint8(139);
writeValue(buffer, value.encode());
} else if (value is TrackMessage) {
} else if (value is StreamingPropertyMessage) {
buffer.putUint8(140);
writeValue(buffer, value.encode());
} else if (value is TrackTypeMessage) {
} else if (value is StreamingPropertyTypeMessage) {
buffer.putUint8(141);
writeValue(buffer, value.encode());
} else if (value is VolumeMessage) {
} else if (value is TrackMessage) {
buffer.putUint8(142);
writeValue(buffer, value.encode());
} else if (value is TrackTypeMessage) {
buffer.putUint8(143);
writeValue(buffer, value.encode());
} else if (value is VolumeMessage) {
buffer.putUint8(144);
writeValue(buffer, value.encode());
} else {
super.writeValue(buffer, value);
}
Expand All @@ -514,30 +572,34 @@ class _VideoPlayerAvplayApiCodec extends StandardMessageCodec {
case 129:
return CreateMessage.decode(readValue(buffer)!);
case 130:
return DurationMessage.decode(readValue(buffer)!);
return DisplayModeMessage.decode(readValue(buffer)!);
case 131:
return GeometryMessage.decode(readValue(buffer)!);
return DurationMessage.decode(readValue(buffer)!);
case 132:
return LoopingMessage.decode(readValue(buffer)!);
return GeometryMessage.decode(readValue(buffer)!);
case 133:
return MixWithOthersMessage.decode(readValue(buffer)!);
return LoopingMessage.decode(readValue(buffer)!);
case 134:
return PlaybackSpeedMessage.decode(readValue(buffer)!);
return MixWithOthersMessage.decode(readValue(buffer)!);
case 135:
return PlayerMessage.decode(readValue(buffer)!);
return PlaybackSpeedMessage.decode(readValue(buffer)!);
case 136:
return PositionMessage.decode(readValue(buffer)!);
return PlayerMessage.decode(readValue(buffer)!);
case 137:
return SelectedTracksMessage.decode(readValue(buffer)!);
return PositionMessage.decode(readValue(buffer)!);
case 138:
return StreamingPropertyMessage.decode(readValue(buffer)!);
return RotationMessage.decode(readValue(buffer)!);
case 139:
return StreamingPropertyTypeMessage.decode(readValue(buffer)!);
return SelectedTracksMessage.decode(readValue(buffer)!);
case 140:
return TrackMessage.decode(readValue(buffer)!);
return StreamingPropertyMessage.decode(readValue(buffer)!);
case 141:
return TrackTypeMessage.decode(readValue(buffer)!);
return StreamingPropertyTypeMessage.decode(readValue(buffer)!);
case 142:
return TrackMessage.decode(readValue(buffer)!);
case 143:
return TrackTypeMessage.decode(readValue(buffer)!);
case 144:
return VolumeMessage.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
Expand Down Expand Up @@ -1059,4 +1121,60 @@ class VideoPlayerAvplayApi {
return;
}
}

Future<bool> setDisplayRotate(RotationMessage arg_msg) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.video_player_avplay.VideoPlayerAvplayApi.setDisplayRotate',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_msg]) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyList.length > 1) {
throw PlatformException(
code: replyList[0]! as String,
message: replyList[1] as String?,
details: replyList[2],
);
} else if (replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (replyList[0] as bool?)!;
}
}

Future<bool> setDisplayMode(DisplayModeMessage arg_msg) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.video_player_avplay.VideoPlayerAvplayApi.setDisplayMode',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_msg]) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyList.length > 1) {
throw PlatformException(
code: replyList[0]! as String,
message: replyList[1] as String?,
details: replyList[2],
);
} else if (replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (replyList[0] as bool?)!;
}
}
}
12 changes: 12 additions & 0 deletions packages/video_player_avplay/lib/src/video_player_tizen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ class VideoPlayerTizen extends VideoPlayerPlatform {
bufferConfigValue: value));
}

@override
Future<bool> setDisplayRotate(int playerId, DisplayRotation rotation) {
return _api.setDisplayRotate(
RotationMessage(playerId: playerId, rotation: rotation.index));
}

@override
Future<bool> setDisplayMode(int playerId, DisplayMode displayMode) {
return _api.setDisplayMode(
DisplayModeMessage(playerId: playerId, displayMode: displayMode.index));
}

@override
Future<void> setStreamingProperty(
int playerId, StreamingPropertyType type, String value) async {
Expand Down
18 changes: 18 additions & 0 deletions packages/video_player_avplay/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,24 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
return _videoPlayerPlatform.setBufferConfig(_playerId, type, value);
}

/// Set the rotate angle of display
Future<bool> setDisplayRotate(DisplayRotation rotation) async {
if (_isDisposedOrNotInitialized) {
return false;
}

return _videoPlayerPlatform.setDisplayRotate(_playerId, rotation);
}

/// Set the video display mode.
Future<bool> setDisplayMode(DisplayMode displayMode) async {
if (_isDisposedOrNotInitialized) {
return false;
}

return _videoPlayerPlatform.setDisplayMode(_playerId, displayMode);
}

/// Sets the playback speed of [this].
///
/// [speed] indicates a speed value with different platforms accepting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
throw UnimplementedError('setBufferConfig() has not been implemented.');
}

/// Set the rotate angle of display.
Future<bool> setDisplayRotate(int playerId, DisplayRotation rotation) {
throw UnimplementedError('setDisplayRotate() has not been implemented.');
}

/// Set the video display mode.
Future<bool> setDisplayMode(int playerId, DisplayMode displayMode) {
throw UnimplementedError('setDisplayMode() has not been implemented.');
}

/// Set streamingengine property.
Future<void> setStreamingProperty(
int playerId, StreamingPropertyType type, String value) {
Expand Down Expand Up @@ -353,6 +363,48 @@ enum BufferConfigType {
bufferingTimeoutInSecForPlay,
}

/// The different types of display rotations that can be set on the player.
enum DisplayRotation {
/// No rotation.
rotation0,

/// 90 degrees rotation.
rotation90,

/// 180 degrees rotation.
rotation180,

/// 270 degrees rotation.
rotation270,
}

/// Sets the video screen mode in the specified display area.
enum DisplayMode {
/// player display mode letter box
letterBox,

/// player display mode origin size
originSize,

/// player display mode full screen
fullScreen,

/// player display mode cropped full
croppedFull,

/// player display mode origin or letter
originOrLetter,

/// player display mode dst roi
dstRoi,

/// player display mode auto aspect ratio
autoAspectRatio,

/// player display mode dst roi auto aspect ratio
dstRoiAutoAspectRatio,
}

/// Event emitted from the platform implementation.
@immutable
class VideoEvent {
Expand Down
20 changes: 20 additions & 0 deletions packages/video_player_avplay/pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ class BufferConfigMessage {
int bufferConfigValue;
}

class RotationMessage {
RotationMessage(
this.playerId,
this.rotation,
);
int playerId;
int rotation;
}

class DisplayModeMessage {
DisplayModeMessage(
this.playerId,
this.displayMode,
);
int playerId;
int displayMode;
}

@HostApi()
abstract class VideoPlayerAvplayApi {
void initialize();
Expand All @@ -134,4 +152,6 @@ abstract class VideoPlayerAvplayApi {
String getStreamingProperty(StreamingPropertyTypeMessage msg);
bool setBufferConfig(BufferConfigMessage msg);
void setStreamingProperty(StreamingPropertyMessage msg);
bool setDisplayRotate(RotationMessage msg);
bool setDisplayMode(DisplayModeMessage msg);
}
Loading
Loading