Bug fix: Use getDuration vs. getTimelineDuration in Effect and Overlay limits calculations.
Change-Id: I5f619807435dc75c285446bfd60327bc1c1ecacd
This commit is contained in:
@@ -57,7 +57,7 @@ public abstract class Effect {
|
||||
throw new IllegalArgumentException("Media item cannot be null");
|
||||
}
|
||||
|
||||
if (startTimeMs + durationMs > mediaItem.getTimelineDuration()) {
|
||||
if (startTimeMs + durationMs > mediaItem.getDuration()) {
|
||||
throw new IllegalArgumentException("Invalid start time and duration");
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public abstract class Effect {
|
||||
* @param durationMs of the effect in milliseconds
|
||||
*/
|
||||
public void setDuration(long durationMs) {
|
||||
if (mStartTimeMs + durationMs > mMediaItem.getTimelineDuration()) {
|
||||
if (mStartTimeMs + durationMs > mMediaItem.getDuration()) {
|
||||
throw new IllegalArgumentException("Duration is too large");
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public abstract class Effect {
|
||||
* of the media item in milliseconds
|
||||
*/
|
||||
public void setStartTime(long startTimeMs) {
|
||||
if (startTimeMs + mDurationMs > mMediaItem.getTimelineDuration()) {
|
||||
if (startTimeMs + mDurationMs > mMediaItem.getDuration()) {
|
||||
throw new IllegalArgumentException("Start time is too large");
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public abstract class Effect {
|
||||
* @param durationMs The duration in milliseconds
|
||||
*/
|
||||
public void setStartTimeAndDuration(long startTimeMs, long durationMs) {
|
||||
if (startTimeMs + durationMs > mMediaItem.getTimelineDuration()) {
|
||||
if (startTimeMs + durationMs > mMediaItem.getDuration()) {
|
||||
throw new IllegalArgumentException("Invalid start time or duration");
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,14 @@ public class MediaImageItem extends MediaItem {
|
||||
adjustEffects();
|
||||
}
|
||||
|
||||
/*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public long getDuration() {
|
||||
return mDurationMs;
|
||||
}
|
||||
|
||||
/*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@@ -173,6 +173,11 @@ public abstract class MediaItem {
|
||||
*/
|
||||
public abstract long getTimelineDuration();
|
||||
|
||||
/**
|
||||
* @return The is the full duration of the media item (not trimmed)
|
||||
*/
|
||||
public abstract long getDuration();
|
||||
|
||||
/**
|
||||
* @return The source file type
|
||||
*/
|
||||
@@ -223,7 +228,7 @@ public abstract class MediaItem {
|
||||
throw new IllegalArgumentException("Effect already exists: " + effect.getId());
|
||||
}
|
||||
|
||||
if (effect.getStartTime() + effect.getDuration() > getTimelineDuration()) {
|
||||
if (effect.getStartTime() + effect.getDuration() > getDuration()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Effect start time + effect duration > media clip duration");
|
||||
}
|
||||
@@ -300,7 +305,7 @@ public abstract class MediaItem {
|
||||
throw new IllegalArgumentException("Overlay already exists: " + overlay.getId());
|
||||
}
|
||||
|
||||
if (overlay.getStartTime() + overlay.getDuration() > getTimelineDuration()) {
|
||||
if (overlay.getStartTime() + overlay.getDuration() > getDuration()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Overlay start time + overlay duration > media clip duration");
|
||||
}
|
||||
@@ -455,7 +460,7 @@ public abstract class MediaItem {
|
||||
}
|
||||
|
||||
if (mEndTransition != null) {
|
||||
if (effect.getStartTime() + effect.getDuration() > getTimelineDuration()
|
||||
if (effect.getStartTime() + effect.getDuration() > getDuration()
|
||||
- mEndTransition.getDuration()) {
|
||||
mEndTransition.invalidate();
|
||||
}
|
||||
@@ -476,7 +481,7 @@ public abstract class MediaItem {
|
||||
}
|
||||
|
||||
if (mEndTransition != null) {
|
||||
if (overlay.getStartTime() + overlay.getDuration() > getTimelineDuration()
|
||||
if (overlay.getStartTime() + overlay.getDuration() > getDuration()
|
||||
- mEndTransition.getDuration()) {
|
||||
mEndTransition.invalidate();
|
||||
}
|
||||
@@ -511,7 +516,7 @@ public abstract class MediaItem {
|
||||
for (Effect effect : effects) {
|
||||
// Adjust the start time if necessary
|
||||
final long effectStartTimeMs;
|
||||
if (effect.getStartTime() > getTimelineDuration()) {
|
||||
if (effect.getStartTime() > getDuration()) {
|
||||
effectStartTimeMs = 0;
|
||||
} else {
|
||||
effectStartTimeMs = effect.getStartTime();
|
||||
@@ -519,8 +524,8 @@ public abstract class MediaItem {
|
||||
|
||||
// Adjust the duration if necessary
|
||||
final long effectDurationMs;
|
||||
if (effectStartTimeMs + effect.getDuration() > getTimelineDuration()) {
|
||||
effectDurationMs = getTimelineDuration() - effectStartTimeMs;
|
||||
if (effectStartTimeMs + effect.getDuration() > getDuration()) {
|
||||
effectDurationMs = getDuration() - effectStartTimeMs;
|
||||
} else {
|
||||
effectDurationMs = effect.getDuration();
|
||||
}
|
||||
@@ -540,7 +545,7 @@ public abstract class MediaItem {
|
||||
for (Overlay overlay : overlays) {
|
||||
// Adjust the start time if necessary
|
||||
final long overlayStartTimeMs;
|
||||
if (overlay.getStartTime() > getTimelineDuration()) {
|
||||
if (overlay.getStartTime() > getDuration()) {
|
||||
overlayStartTimeMs = 0;
|
||||
} else {
|
||||
overlayStartTimeMs = overlay.getStartTime();
|
||||
@@ -548,8 +553,8 @@ public abstract class MediaItem {
|
||||
|
||||
// Adjust the duration if necessary
|
||||
final long overlayDurationMs;
|
||||
if (overlayStartTimeMs + overlay.getDuration() > getTimelineDuration()) {
|
||||
overlayDurationMs = getTimelineDuration() - overlayStartTimeMs;
|
||||
if (overlayStartTimeMs + overlay.getDuration() > getDuration()) {
|
||||
overlayDurationMs = getDuration() - overlayStartTimeMs;
|
||||
} else {
|
||||
overlayDurationMs = overlay.getDuration();
|
||||
}
|
||||
|
||||
@@ -243,16 +243,16 @@ public class MediaVideoItem extends MediaItem {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The duration of the video clip
|
||||
/*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public long getDuration() {
|
||||
return mDurationMs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The timeline duration. This is the actual duration in the
|
||||
* timeline (trimmed duration)
|
||||
/*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public long getTimelineDuration() {
|
||||
|
||||
@@ -60,7 +60,7 @@ public abstract class Overlay {
|
||||
throw new IllegalArgumentException("Media item cannot be null");
|
||||
}
|
||||
|
||||
if (startTimeMs + durationMs > mediaItem.getTimelineDuration()) {
|
||||
if (startTimeMs + durationMs > mediaItem.getDuration()) {
|
||||
throw new IllegalArgumentException("Invalid start time and duration");
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public abstract class Overlay {
|
||||
* @param durationMs The duration in milliseconds
|
||||
*/
|
||||
public void setDuration(long durationMs) {
|
||||
if (mStartTimeMs + durationMs > mMediaItem.getTimelineDuration()) {
|
||||
if (mStartTimeMs + durationMs > mMediaItem.getDuration()) {
|
||||
throw new IllegalArgumentException("Duration is too large");
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public abstract class Overlay {
|
||||
* @param startTimeMs start time in milliseconds
|
||||
*/
|
||||
public void setStartTime(long startTimeMs) {
|
||||
if (startTimeMs + mDurationMs > mMediaItem.getTimelineDuration()) {
|
||||
if (startTimeMs + mDurationMs > mMediaItem.getDuration()) {
|
||||
throw new IllegalArgumentException("Start time is too large");
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public abstract class Overlay {
|
||||
* @param durationMs The duration in milliseconds
|
||||
*/
|
||||
public void setStartTimeAndDuration(long startTimeMs, long durationMs) {
|
||||
if (startTimeMs + durationMs > mMediaItem.getTimelineDuration()) {
|
||||
if (startTimeMs + durationMs > mMediaItem.getDuration()) {
|
||||
throw new IllegalArgumentException("Invalid start time or duration");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user