Skip to content

Commit

Permalink
feat(android): add new constants for video scaling (#11148)
Browse files Browse the repository at this point in the history
* feat(android): add new constants for video scaling

* refactor(android): improve message formatting and add docs
  • Loading branch information
ypbnv authored and keerthi1032 committed Sep 11, 2019
1 parent 44a5968 commit 16f04c5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
35 changes: 31 additions & 4 deletions android/modules/media/src/java/android/widget/TiVideoView8.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class TiVideoView8 extends SurfaceView implements MediaPlayerControl
{
private static final String TAG = "TiVideoView8";
// TITANIUM
private int mScalingMode = MediaModule.VIDEO_SCALING_ASPECT_FIT;
private int mScalingMode = MediaModule.VIDEO_SCALING_RESIZE_ASPECT;
// settable by the client
private Uri mUri;
@SuppressWarnings("unused")
Expand Down Expand Up @@ -179,6 +179,29 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
}
}

private void constantDeprecationWarning(int constant)
{
String message = null;
final String MESSAGE_FORMAT = "%s has been deprecated. Use %s instead.";
switch (constant) {
case MediaModule.VIDEO_SCALING_ASPECT_FILL:
message = String.format(MESSAGE_FORMAT, "Ti.Media.VIDEO_SCALING_ASPECT_FILL",
"Ti.Media.VIDEO_SCALING_RESIZE_ASPECT_FILL");
break;
case MediaModule.VIDEO_SCALING_ASPECT_FIT:
message = String.format(MESSAGE_FORMAT, "Ti.Media.VIDEO_SCALING_ASPECT_FIT",
"Ti.Media.VIDEO_SCALING_RESIZE_ASPECT_FIT");
break;
case MediaModule.VIDEO_SCALING_MODE_FILL:
message =
String.format(MESSAGE_FORMAT, "Ti.Media.VIDEO_SCALING_MODE_FILL", "Ti.Media.VIDEO_SCALING_RESIZE");
break;
}
if (message != null) {
Log.w("VideoPlayerProxy", message);
}
}

protected void measureVideo(int videoWidth, int videoHeight, int widthMeasureSpec, int heightMeasureSpec)
{
Log.e(TAG,
Expand All @@ -196,28 +219,32 @@ protected void measureVideo(int videoWidth, int videoHeight, int widthMeasureSpe
height = videoHeight;
break;
}
case MediaModule.VIDEO_SCALING_ASPECT_FILL: {
case MediaModule.VIDEO_SCALING_ASPECT_FILL:
case MediaModule.VIDEO_SCALING_RESIZE_ASPECT_FILL: {
if (videoWidth * height > width * videoHeight) {
width = height * videoWidth / videoHeight;
} else if (videoWidth * height < width * videoHeight) {
height = width * videoHeight / videoWidth;
}
break;
}
case MediaModule.VIDEO_SCALING_ASPECT_FIT: {
case MediaModule.VIDEO_SCALING_ASPECT_FIT:
case MediaModule.VIDEO_SCALING_RESIZE_ASPECT: {
if (videoWidth * height > width * videoHeight) {
height = width * videoHeight / videoWidth;
} else if (videoWidth * height < width * videoHeight) {
width = height * videoWidth / videoHeight;
}
break;
}
case MediaModule.VIDEO_SCALING_MODE_FILL: {
case MediaModule.VIDEO_SCALING_MODE_FILL:
case MediaModule.VIDEO_SCALING_RESIZE: {
width = MeasureSpec.getSize(widthMeasureSpec);
height = MeasureSpec.getSize(heightMeasureSpec);
break;
}
}
constantDeprecationWarning(mScalingMode);
}
String model = Build.MODEL;
if (model != null && model.equals("SPH-P100")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public class MediaModule extends KrollModule implements Handler.Callback
public static final int VIDEO_SCALING_ASPECT_FIT = 2;
@Kroll.constant
public static final int VIDEO_SCALING_MODE_FILL = 3;
@Kroll.constant
public static final int VIDEO_SCALING_RESIZE = 4;
@Kroll.constant
public static final int VIDEO_SCALING_RESIZE_ASPECT = 5;
@Kroll.constant
public static final int VIDEO_SCALING_RESIZE_ASPECT_FILL = 6;

@Kroll.constant
public static final int VIDEO_CONTROL_DEFAULT = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
TiC.PROPERTY_URL,
TiC.PROPERTY_INITIAL_PLAYBACK_TIME,
TiC.PROPERTY_DURATION,
"contentURL",
TiC.PROPERTY_CONTENT_URL,
TiC.PROPERTY_AUTOPLAY,
TiC.PROPERTY_END_PLAYBACK_TIME,
TiC.PROPERTY_PLAYABLE_DURATION,
Expand Down
12 changes: 6 additions & 6 deletions apidoc/Titanium/Media/Media.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1506,20 +1506,20 @@ properties:
summary: Specifies that the video should be stretched to fill the bounds of layer.
type: String
permission: read-only
platforms: [iphone, ipad]
since: "7.0.0"
platforms: [iphone, ipad, android]
since: {iphone: "7.0.0", ipad: "7.0.0", android: "8.3.0"}
- name: VIDEO_SCALING_RESIZE_ASPECT
summary: Specifies that the player should preserve the aspect ratio of video and fit the video within the bounds of layer.
type: String
permission: read-only
platforms: [iphone, ipad]
since: "7.0.0"
platforms: [iphone, ipad, android]
since: {iphone: "7.0.0", ipad: "7.0.0", android: "8.3.0"}
- name: VIDEO_SCALING_RESIZE_ASPECT_FILL
summary: Specifies that the player should preserve the aspect ratio of video and fill the bounds of layer.
type: String
permission: read-only
platforms: [iphone, ipad]
since: "7.0.0"
platforms: [iphone, ipad, android]
since: {iphone: "7.0.0", ipad: "7.0.0", android: "8.3.0"}

- name: VIDEO_SOURCE_TYPE_FILE
deprecated:
Expand Down

0 comments on commit 16f04c5

Please sign in to comment.