Effect.java revision 5665fd6ac2b2d3a00b3addf1ae897426896935d6
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.media.videoeditor; 18 19/** 20 * This is the super class for all effects. An effect can only be applied to a 21 * single media item. If one wants to apply the same effect to multiple media 22 * items, multiple @{MediaItem.addEffect(Effect)} call must be invoked on each 23 * of the MediaItem objects. 24 * {@hide} 25 */ 26public abstract class Effect { 27 // Instance variables 28 private final String mUniqueId; 29 // The effect owner 30 private final MediaItem mMediaItem; 31 protected long mDurationMs; 32 // The start time of the effect relative to the media item timeline 33 protected long mStartTimeMs; 34 35 /** 36 * Default constructor 37 */ 38 @SuppressWarnings("unused") 39 private Effect() { 40 mMediaItem = null; 41 mUniqueId = null; 42 mStartTimeMs = 0; 43 mDurationMs = 0; 44 } 45 46 /** 47 * Constructor 48 * 49 * @param mediaItem The media item owner 50 * @param effectId The effect id 51 * @param startTimeMs The start time relative to the media item to which it 52 * is applied 53 * @param durationMs The effect duration in milliseconds 54 */ 55 public Effect(MediaItem mediaItem, String effectId, long startTimeMs, long durationMs) { 56 if (mediaItem == null) { 57 throw new IllegalArgumentException("Media item cannot be null"); 58 } 59 60 if (startTimeMs + durationMs > mediaItem.getTimelineDuration()) { 61 throw new IllegalArgumentException("Invalid start time and duration"); 62 } 63 64 mMediaItem = mediaItem; 65 mUniqueId = effectId; 66 mStartTimeMs = startTimeMs; 67 mDurationMs = durationMs; 68 } 69 70 /** 71 * @return The id of the effect 72 */ 73 public String getId() { 74 return mUniqueId; 75 } 76 77 /** 78 * Set the duration of the effect. If a preview or export is in progress, 79 * then this change is effective for next preview or export session. s 80 * 81 * @param durationMs of the effect in milliseconds 82 */ 83 public void setDuration(long durationMs) { 84 if (mStartTimeMs + durationMs > mMediaItem.getTimelineDuration()) { 85 throw new IllegalArgumentException("Duration is too large"); 86 } 87 88 mDurationMs = durationMs; 89 90 mMediaItem.invalidateTransitions(this); 91 } 92 93 /** 94 * Get the duration of the effect 95 * 96 * @return The duration of the effect in milliseconds 97 */ 98 public long getDuration() { 99 return mDurationMs; 100 } 101 102 /** 103 * Set start time of the effect. If a preview or export is in progress, then 104 * this change is effective for next preview or export session. 105 * 106 * @param startTimeMs The start time of the effect relative to the beginning 107 * of the media item in milliseconds 108 */ 109 public void setStartTime(long startTimeMs) { 110 if (startTimeMs + mDurationMs > mMediaItem.getTimelineDuration()) { 111 throw new IllegalArgumentException("Start time is too large"); 112 } 113 114 mStartTimeMs = startTimeMs; 115 116 mMediaItem.invalidateTransitions(this); 117 } 118 119 /** 120 * @return The start time in milliseconds 121 */ 122 public long getStartTime() { 123 return mStartTimeMs; 124 } 125 126 /** 127 * @return The media item owner 128 */ 129 public MediaItem getMediaItem() { 130 return mMediaItem; 131 } 132 133 /* 134 * {@inheritDoc} 135 */ 136 @Override 137 public boolean equals(Object object) { 138 if (!(object instanceof Effect)) { 139 return false; 140 } 141 return mUniqueId.equals(((Effect)object).mUniqueId); 142 } 143 144 /* 145 * {@inheritDoc} 146 */ 147 @Override 148 public int hashCode() { 149 return mUniqueId.hashCode(); 150 } 151} 152