Skip to content

Commit cb6662a

Browse files
James DongAndroid (Google) Code Review
authored andcommitted
Merge "Add video scaling mode support with a new public method in MediaPlayer.java class" into jb-dev
2 parents f72d392 + 454014e commit cb6662a

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

api/current.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11192,6 +11192,7 @@ package android.media {
1119211192
method public void setOnVideoSizeChangedListener(android.media.MediaPlayer.OnVideoSizeChangedListener);
1119311193
method public void setScreenOnWhilePlaying(boolean);
1119411194
method public void setSurface(android.view.Surface);
11195+
method public void setVideoScalingMode(int);
1119511196
method public void setVolume(float, float);
1119611197
method public void setWakeMode(android.content.Context, int);
1119711198
method public void start() throws java.lang.IllegalStateException;
@@ -11207,6 +11208,8 @@ package android.media {
1120711208
field public static final int MEDIA_INFO_UNKNOWN = 1; // 0x1
1120811209
field public static final int MEDIA_INFO_VIDEO_TRACK_LAGGING = 700; // 0x2bc
1120911210
field public static final java.lang.String MEDIA_MIMETYPE_TEXT_SUBRIP = "application/x-subrip";
11211+
field public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT = 1; // 0x1
11212+
field public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING = 2; // 0x2
1121011213
}
1121111214

1121211215
public static abstract interface MediaPlayer.OnBufferingUpdateListener {

media/java/android/media/MediaPlayer.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@
394394
* <td>{} </p></td>
395395
* <td>This method can be called in any state and calling it does not change
396396
* the object state. </p></td></tr>
397+
* <tr><td>setVideoScalingMode </p></td>
398+
* <td>{Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted} </p></td>
399+
* <td>{Idle, Error}</p></td>
400+
* <td>Successful invoke of this method does not change the state.</p></td></tr>
397401
* <tr><td>setLooping </p></td>
398402
* <td>{Idle, Initialized, Stopped, Prepared, Started, Paused,
399403
* PlaybackCompleted}</p></td>
@@ -599,6 +603,7 @@ public MediaPlayer() {
599603
private static final int INVOKE_ID_ADD_EXTERNAL_SOURCE_FD = 3;
600604
private static final int INVOKE_ID_SELECT_TRACK = 4;
601605
private static final int INVOKE_ID_DESELECT_TRACK = 5;
606+
private static final int INVOKE_ID_SET_VIDEO_SCALE_MODE = 6;
602607

603608
/**
604609
* Create a request parcel which can be routed to the native media
@@ -691,6 +696,58 @@ public void setSurface(Surface surface) {
691696
updateSurfaceScreenOn();
692697
}
693698

699+
/* Do not change these video scaling mode values below without updating
700+
* their counterparts in system/window.h! Please do not forget to update
701+
* {@link #isVideoScalingModeSupported} when new video scaling modes
702+
* are added.
703+
*/
704+
/**
705+
* Specifies a video scaling mode. The content is stretched to the
706+
* surface rendering area. When the surface has the same aspect ratio
707+
* as the content, the aspect ratio of the content is maintained;
708+
* otherwise, the aspect ratio of the content is not maintained when video
709+
* is being rendered. Unlike {@ #VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING},
710+
* there is no content cropping with this video scaling mode.
711+
*/
712+
public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT = 1;
713+
714+
/**
715+
* Specifies a video scaling mode. The content is scaled, maintaining
716+
* its aspect ratio. The whole surface area is always used. When the
717+
* aspect ratio of the content is the same as the surface, no content
718+
* is cropped; otherwise, content is cropped to fit the surface.
719+
*/
720+
public static final int VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING = 2;
721+
/**
722+
* Sets video scaling mode. To make the target video scaling mode
723+
* effective during playback, this method must be called after
724+
* data source is set. If not called, the default video
725+
* scaling mode is {@link #VIDEO_SCALING_MODE_SCALE_TO_FIT}.
726+
*
727+
* <p> The supported video scaling modes are:
728+
* <ul>
729+
* <li> {@link #VIDEO_SCALING_MODE_SCALE_TO_FIT}
730+
* <li> {@link #VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING}
731+
* </ul>
732+
*
733+
* @param mode target video scaling mode. Most be one of the supported
734+
* video scaling modes; otherwise, IllegalArgumentException will be thrown.
735+
*
736+
* @see MediaPlayer#VIDEO_SCALING_MODE_SCALE_TO_FIT
737+
* @see MediaPlayer#VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
738+
*/
739+
public void setVideoScalingMode(int mode) {
740+
if (isVideoScalingModeSupported(mode)) {
741+
final String msg = "Scaling mode " + mode + " is not supported";
742+
throw new IllegalArgumentException(msg);
743+
}
744+
Parcel request = Parcel.obtain();
745+
Parcel reply = Parcel.obtain();
746+
request.writeInterfaceToken(IMEDIA_PLAYER);
747+
request.writeInt(INVOKE_ID_SET_VIDEO_SCALE_MODE);
748+
invoke(request, reply);
749+
}
750+
694751
/**
695752
* Convenience method to create a MediaPlayer for a given Uri.
696753
* On success, {@link #prepare()} will already have been called and must not be called again.
@@ -2319,4 +2376,11 @@ public void setOnInfoListener(OnInfoListener listener)
23192376

23202377
private OnInfoListener mOnInfoListener;
23212378

2379+
/*
2380+
* Test whether a given video scaling mode is supported.
2381+
*/
2382+
private boolean isVideoScalingModeSupported(int mode) {
2383+
return (mode == VIDEO_SCALING_MODE_SCALE_TO_FIT ||
2384+
mode == VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
2385+
}
23222386
}

0 commit comments

Comments
 (0)