|
394 | 394 | * <td>{} </p></td> |
395 | 395 | * <td>This method can be called in any state and calling it does not change |
396 | 396 | * 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> |
397 | 401 | * <tr><td>setLooping </p></td> |
398 | 402 | * <td>{Idle, Initialized, Stopped, Prepared, Started, Paused, |
399 | 403 | * PlaybackCompleted}</p></td> |
@@ -599,6 +603,7 @@ public MediaPlayer() { |
599 | 603 | private static final int INVOKE_ID_ADD_EXTERNAL_SOURCE_FD = 3; |
600 | 604 | private static final int INVOKE_ID_SELECT_TRACK = 4; |
601 | 605 | private static final int INVOKE_ID_DESELECT_TRACK = 5; |
| 606 | + private static final int INVOKE_ID_SET_VIDEO_SCALE_MODE = 6; |
602 | 607 |
|
603 | 608 | /** |
604 | 609 | * Create a request parcel which can be routed to the native media |
@@ -691,6 +696,58 @@ public void setSurface(Surface surface) { |
691 | 696 | updateSurfaceScreenOn(); |
692 | 697 | } |
693 | 698 |
|
| 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 | + |
694 | 751 | /** |
695 | 752 | * Convenience method to create a MediaPlayer for a given Uri. |
696 | 753 | * On success, {@link #prepare()} will already have been called and must not be called again. |
@@ -2319,4 +2376,11 @@ public void setOnInfoListener(OnInfoListener listener) |
2319 | 2376 |
|
2320 | 2377 | private OnInfoListener mOnInfoListener; |
2321 | 2378 |
|
| 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 | + } |
2322 | 2386 | } |
0 commit comments