Skip to content

Commit

Permalink
feat: fullscreen update, add fs parameter, check width > height when …
Browse files Browse the repository at this point in the history
…orientation (#125)

* feat: add userdata opaque in FijkValue

* feat: add fs parameter for FijkView

Set fs false to make your custom full screen mode

* feat: do not perform change orientation if width < height
  • Loading branch information
befovy authored Dec 4, 2019
1 parent 1062282 commit 74779fe
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 22 deletions.
21 changes: 13 additions & 8 deletions android/src/main/java/com/befovy/fijkplayer/FijkPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,22 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
break;
}
case "setOrientationPortrait":
boolean changedPort = false;
if (activity != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
int current_orientation = activity.getResources().getConfiguration().orientation;
if (current_orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
changedPort = true;
}
}
result.success(null);
result.success(changedPort);
break;
case "setOrientationLandscape":
boolean changed = false;
boolean changedLand = false;
if (activity != null) {
int current_orientation = activity.getResources().getConfiguration().orientation;
if (current_orientation == Configuration.ORIENTATION_PORTRAIT) {
Expand All @@ -202,10 +207,10 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
changed = true;
changedLand = true;
}
}
result.success(changed);
result.success(changedLand);
break;
case "setOrientationAuto":
if (activity != null) {
Expand Down
25 changes: 16 additions & 9 deletions ios/Classes/FijkPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,23 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
supportedInterfaceOrientationsForWindow:nil];
UIDeviceOrientation deviceOrientation =
[UIDevice currentDevice].orientation;
if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown &&
(mask & UIInterfaceOrientationMaskPortraitUpsideDown))
[[UIDevice currentDevice]
setValue:@(UIInterfaceOrientationPortraitUpsideDown)
forKey:@"orientation"];
else if (mask & UIInterfaceOrientationMaskPortrait)
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait)
forKey:@"orientation"];
BOOL changed = NO;
if (deviceOrientation != UIDeviceOrientationPortrait &&
deviceOrientation != UIDeviceOrientationPortraitUpsideDown) {
if (mask & UIInterfaceOrientationMaskPortraitUpsideDown) {
[[UIDevice currentDevice]
setValue:@(UIInterfaceOrientationPortraitUpsideDown)
forKey:@"orientation"];
changed = YES;
} else if (mask & UIInterfaceOrientationMaskPortrait) {
[[UIDevice currentDevice]
setValue:@(UIInterfaceOrientationPortrait)
forKey:@"orientation"];
changed = YES;
}
}
[UIViewController attemptRotationToDeviceOrientation];
result(nil);
result(@(changed));
} else if ([@"setOrientationLandscape" isEqualToString:call.method]) {
UIInterfaceOrientationMask mask = [[UIApplication sharedApplication]
supportedInterfaceOrientationsForWindow:nil];
Expand Down
2 changes: 1 addition & 1 deletion lib/core/fijkplugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FijkPlugin {
}

/// Only works on Android and iOS
static Future<void> setOrientationPortrait() {
static Future<bool> setOrientationPortrait() {
if (isDesktop()) return Future.value();
// ios crash Supported orientations has no common orientation with the application
if (Platform.isAndroid) {
Expand Down
9 changes: 8 additions & 1 deletion lib/core/fijkvalue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ class FijkValue {

final FijkException exception;

/// Userdata, set and get by fijkplayer's user.
final dynamic opaque;

/// A constructor requires all value.
const FijkValue({
@required this.prepared,
Expand All @@ -174,6 +177,7 @@ class FijkValue {
@required this.duration,
@required this.fullScreen,
@required this.exception,
@required this.opaque,
});

/// Construct FijkValue with uninitialized value
Expand All @@ -189,6 +193,7 @@ class FijkValue {
duration: const Duration(),
fullScreen: false,
exception: FijkException.noException,
opaque: null,
);

/// Return new FijkValue which combines the old value and the assigned new value
Expand All @@ -203,6 +208,7 @@ class FijkValue {
Duration duration,
bool fullScreen,
FijkException exception,
dynamic opaque,
}) {
return FijkValue(
prepared: prepared ?? this.prepared,
Expand All @@ -214,6 +220,7 @@ class FijkValue {
rotate: rotate ?? this.rotate,
duration: duration ?? this.duration,
fullScreen: fullScreen ?? this.fullScreen,
opaque: opaque ?? this.opaque,
exception: exception ?? this.exception,
);
}
Expand All @@ -227,7 +234,7 @@ class FijkValue {

@override
int get hashCode => hashValues(prepared, completed, state, size, rotate,
duration, fullScreen, exception);
duration, fullScreen, exception, opaque);

@override
String toString() {
Expand Down
41 changes: 38 additions & 3 deletions lib/core/fijkview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class FijkView extends StatefulWidget {
this.fsFit = FijkFit.contain,
this.panelBuilder = defaultFijkPanelBuilder,
this.color = const Color(0xFF607D8B),
this.fs = true,
}) : assert(player != null);

/// The player that need display video by this [FijkView].
Expand All @@ -149,6 +150,15 @@ class FijkView extends StatefulWidget {
/// If null, the height will be as big as possible.
final double height;

/// Enable or disable the full screen
///
/// If [fs] is true, FijkView make response to the [FijkValue.fullScreen] value changed,
/// and push o new full screen mode page when [FijkValue.fullScreen] is true, pop full screen page when [FijkValue.fullScreen] become false.
///
/// If [fs] is false, FijkView never make response to the change of [FijkValue.fullScreen].
/// But you can still call [FijkPlayer.enterFullScreen] and [FijkPlayer.exitFullScreen] and make your own full screen pages.
final bool fs;

@override
createState() => _FijkViewState();
}
Expand All @@ -165,7 +175,14 @@ class _FijkViewState extends State<FijkView> {
void initState() {
super.initState();
_nativeSetup();
widget.player.addListener(_fijkValueListener);
Size s = widget.player.value.size;
if (s != null) {
_vWidth = s.width;
_vHeight = s.height;
}
if (widget.fs) {
widget.player.addListener(_fijkValueListener);
}
}

Future<void> _nativeSetup() async {
Expand All @@ -186,6 +203,11 @@ class _FijkViewState extends State<FijkView> {
Navigator.of(context).pop();
_fullScreen = false;
}

if (value.size != null && value.prepared) {
_vWidth = value.size.width;
_vHeight = value.size.height;
}
}

@override
Expand Down Expand Up @@ -219,14 +241,27 @@ class _FijkViewState extends State<FijkView> {
);

await SystemChrome.setEnabledSystemUIOverlays([]);
final changed = await FijkPlugin.setOrientationLandscape();
bool changed = false;
if (_vWidth >= _vHeight) {
if (MediaQuery.of(context).orientation == Orientation.portrait)
changed = await FijkPlugin.setOrientationLandscape();
} else {
if (MediaQuery.of(context).orientation == Orientation.landscape)
changed = await FijkPlugin.setOrientationPortrait();
}

await Navigator.of(context).push(route);
_fullScreen = false;
widget.player.exitFullScreen();
await SystemChrome.setEnabledSystemUIOverlays(
[SystemUiOverlay.top, SystemUiOverlay.bottom]);
if (changed) await FijkPlugin.setOrientationPortrait();
if (changed) {
if (_vWidth >= _vHeight) {
await FijkPlugin.setOrientationPortrait();
} else {
await FijkPlugin.setOrientationLandscape();
}
}
}

@override
Expand Down

0 comments on commit 74779fe

Please sign in to comment.