diff --git a/media/java/android/media/videoeditor/MediaImageItem.java b/media/java/android/media/videoeditor/MediaImageItem.java index df3c5fb1e60b8..d2f3694e778c4 100755 --- a/media/java/android/media/videoeditor/MediaImageItem.java +++ b/media/java/android/media/videoeditor/MediaImageItem.java @@ -163,7 +163,9 @@ public class MediaImageItem extends MediaItem { public void setDuration(long durationMs) { mDurationMs = durationMs; - adjustElementsDuration(); + adjustTransitions(); + adjustOverlays(); + adjustEffects(); } /* diff --git a/media/java/android/media/videoeditor/MediaItem.java b/media/java/android/media/videoeditor/MediaItem.java index d9c38af150853..40d36190ee72e 100755 --- a/media/java/android/media/videoeditor/MediaItem.java +++ b/media/java/android/media/videoeditor/MediaItem.java @@ -40,13 +40,21 @@ public abstract class MediaItem { * clip are rendered black. */ public static final int RENDERING_MODE_BLACK_BORDER = 0; + /** * When using the RENDERING_MODE_STRETCH rendering mode video frames are * stretched horizontally or vertically to match the current aspect ratio of - * the movie. + * the video editor. */ public static final int RENDERING_MODE_STRETCH = 1; + /** + * When using the RENDERING_MODE_CROPPING rendering mode video frames are + * scaled horizontally or vertically by preserving the original aspect + * ratio of the media item. + */ + public static final int RENDERING_MODE_CROPPING = 2; + // The unique id of the MediaItem private final String mUniqueId; @@ -476,10 +484,9 @@ public abstract class MediaItem { } /** - * Adjust the duration of effects, overlays and transitions. - * This method will be called after a media item duration is changed. + * Adjust the duration transitions. */ - protected void adjustElementsDuration() { + protected void adjustTransitions() { // Check if the duration of transitions need to be adjusted if (mBeginTransition != null) { final long maxDurationMs = mBeginTransition.getMaximumDuration(); @@ -494,31 +501,12 @@ public abstract class MediaItem { mEndTransition.setDuration(maxDurationMs); } } + } - final List overlays = getAllOverlays(); - for (Overlay overlay : overlays) { - // Adjust the start time if necessary - final long overlayStartTimeMs; - if (overlay.getStartTime() > getTimelineDuration()) { - overlayStartTimeMs = 0; - } else { - overlayStartTimeMs = overlay.getStartTime(); - } - - // Adjust the duration if necessary - final long overlayDurationMs; - if (overlayStartTimeMs + overlay.getDuration() > getTimelineDuration()) { - overlayDurationMs = getTimelineDuration() - overlayStartTimeMs; - } else { - overlayDurationMs = overlay.getDuration(); - } - - if (overlayStartTimeMs != overlay.getStartTime() || - overlayDurationMs != overlay.getDuration()) { - overlay.setStartTimeAndDuration(overlayStartTimeMs, overlayDurationMs); - } - } - + /** + * Adjust the start time and/or duration of effects. + */ + protected void adjustEffects() { final List effects = getAllEffects(); for (Effect effect : effects) { // Adjust the start time if necessary @@ -543,4 +531,33 @@ public abstract class MediaItem { } } } + + /** + * Adjust the start time and/or duration of overlays. + */ + protected void adjustOverlays() { + final List overlays = getAllOverlays(); + for (Overlay overlay : overlays) { + // Adjust the start time if necessary + final long overlayStartTimeMs; + if (overlay.getStartTime() > getTimelineDuration()) { + overlayStartTimeMs = 0; + } else { + overlayStartTimeMs = overlay.getStartTime(); + } + + // Adjust the duration if necessary + final long overlayDurationMs; + if (overlayStartTimeMs + overlay.getDuration() > getTimelineDuration()) { + overlayDurationMs = getTimelineDuration() - overlayStartTimeMs; + } else { + overlayDurationMs = overlay.getDuration(); + } + + if (overlayStartTimeMs != overlay.getStartTime() || + overlayDurationMs != overlay.getDuration()) { + overlay.setStartTimeAndDuration(overlayStartTimeMs, overlayDurationMs); + } + } + } } diff --git a/media/java/android/media/videoeditor/MediaVideoItem.java b/media/java/android/media/videoeditor/MediaVideoItem.java index f71f4f4a1eb80..341bf8e2b0e41 100755 --- a/media/java/android/media/videoeditor/MediaVideoItem.java +++ b/media/java/android/media/videoeditor/MediaVideoItem.java @@ -155,7 +155,11 @@ public class MediaVideoItem extends MediaItem { mBeginBoundaryTimeMs = beginMs; mEndBoundaryTimeMs = endMs; - adjustElementsDuration(); + adjustTransitions(); + + // Note that the start and duration of any effects and overlays are + // not adjusted nor are they automatically removed if they fall + // outside the new boundaries. } /**