use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorImpl method removeMediaItem.
/*
* {@inheritDoc}
*/
public synchronized MediaItem removeMediaItem(String mediaItemId) {
final String firstItemString = mMediaItems.get(0).getId();
final MediaItem mediaItem = getMediaItem(mediaItemId);
if (mediaItem != null) {
mMANativeHelper.setGeneratePreview(true);
/**
* Remove the media item
*/
mMediaItems.remove(mediaItem);
if (mediaItem instanceof MediaImageItem) {
((MediaImageItem) mediaItem).invalidate();
}
final List<Overlay> overlays = mediaItem.getAllOverlays();
if (overlays.size() > 0) {
for (Overlay overlay : overlays) {
if (overlay instanceof OverlayFrame) {
final OverlayFrame overlayFrame = (OverlayFrame) overlay;
overlayFrame.invalidate();
}
}
}
/**
* Remove the adjacent transitions
*/
removeAdjacentTransitions(mediaItem);
computeTimelineDuration();
}
/**
* If string equals first mediaItem, then
* generate Project thumbnail
*/
if (firstItemString.equals(mediaItemId)) {
generateProjectThumbnail();
}
if (mediaItem instanceof MediaVideoItem) {
/**
* Delete the graph file
*/
((MediaVideoItem) mediaItem).invalidate();
}
return mediaItem;
}
use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorImpl method removeMediaItem.
private synchronized MediaItem removeMediaItem(String mediaItemId, boolean flag) {
final String firstItemString = mMediaItems.get(0).getId();
final MediaItem mediaItem = getMediaItem(mediaItemId);
if (mediaItem != null) {
mMANativeHelper.setGeneratePreview(true);
/**
* Remove the media item
*/
mMediaItems.remove(mediaItem);
/**
* Remove the adjacent transitions
*/
removeAdjacentTransitions(mediaItem);
computeTimelineDuration();
}
/**
* If string equals first mediaItem, then
* generate Project thumbail
*/
if (firstItemString.equals(mediaItemId)) {
generateProjectThumbnail();
}
return mediaItem;
}
use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorImpl method removeTransitionAfter.
/**
* Remove the transition after this media item
*
* @param mediaItem The media item
*/
private void removeTransitionAfter(int index) {
final MediaItem mediaItem = mMediaItems.get(index);
final Iterator<Transition> it = mTransitions.iterator();
while (it.hasNext()) {
Transition t = it.next();
if (t.getAfterMediaItem() == mediaItem) {
mMANativeHelper.setGeneratePreview(true);
it.remove();
t.invalidate();
mediaItem.setEndTransition(null);
/**
* Invalidate the reference in the next media item
*/
if (index < mMediaItems.size() - 1) {
mMediaItems.get(index + 1).setBeginTransition(null);
}
break;
}
}
}
use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorImpl method parseTransition.
/**
* Parse the transition
*
* @param parser The parser
* @param ignoredMediaItems The list of ignored media items
*
* @return The transition
*/
private Transition parseTransition(XmlPullParser parser, List<String> ignoredMediaItems) {
final String transitionId = parser.getAttributeValue("", ATTR_ID);
final String type = parser.getAttributeValue("", ATTR_TYPE);
final long durationMs = Long.parseLong(parser.getAttributeValue("", ATTR_DURATION));
final int behavior = Integer.parseInt(parser.getAttributeValue("", ATTR_BEHAVIOR));
final String beforeMediaItemId = parser.getAttributeValue("", ATTR_BEFORE_MEDIA_ITEM_ID);
final MediaItem beforeMediaItem;
if (beforeMediaItemId != null) {
if (ignoredMediaItems.contains(beforeMediaItemId)) {
// This transition is ignored
return null;
}
beforeMediaItem = getMediaItem(beforeMediaItemId);
} else {
beforeMediaItem = null;
}
final String afterMediaItemId = parser.getAttributeValue("", ATTR_AFTER_MEDIA_ITEM_ID);
final MediaItem afterMediaItem;
if (afterMediaItemId != null) {
if (ignoredMediaItems.contains(afterMediaItemId)) {
// This transition is ignored
return null;
}
afterMediaItem = getMediaItem(afterMediaItemId);
} else {
afterMediaItem = null;
}
final Transition transition;
if (TransitionAlpha.class.getSimpleName().equals(type)) {
final int blending = Integer.parseInt(parser.getAttributeValue("", ATTR_BLENDING));
final String maskFilename = parser.getAttributeValue("", ATTR_MASK);
final boolean invert = Boolean.getBoolean(parser.getAttributeValue("", ATTR_INVERT));
transition = new TransitionAlpha(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior, maskFilename, blending, invert);
} else if (TransitionCrossfade.class.getSimpleName().equals(type)) {
transition = new TransitionCrossfade(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior);
} else if (TransitionSliding.class.getSimpleName().equals(type)) {
final int direction = Integer.parseInt(parser.getAttributeValue("", ATTR_DIRECTION));
transition = new TransitionSliding(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior, direction);
} else if (TransitionFadeBlack.class.getSimpleName().equals(type)) {
transition = new TransitionFadeBlack(transitionId, afterMediaItem, beforeMediaItem, durationMs, behavior);
} else {
throw new IllegalArgumentException("Invalid transition type: " + type);
}
final boolean isTransitionGenerated = Boolean.parseBoolean(parser.getAttributeValue("", ATTR_IS_TRANSITION_GENERATED));
if (isTransitionGenerated == true) {
final String transitionFile = parser.getAttributeValue("", ATTR_GENERATED_TRANSITION_CLIP);
if (new File(transitionFile).exists()) {
transition.setFilename(transitionFile);
} else {
transition.setFilename(null);
}
}
// Use the transition
if (beforeMediaItem != null) {
beforeMediaItem.setBeginTransition(transition);
}
if (afterMediaItem != null) {
afterMediaItem.setEndTransition(transition);
}
return transition;
}
use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorImpl method removeTransition.
/*
* {@inheritDoc}
*/
public synchronized Transition removeTransition(String transitionId) {
final Transition transition = getTransition(transitionId);
if (transition == null) {
throw new IllegalStateException("Transition not found: " + transitionId);
}
mMANativeHelper.setGeneratePreview(true);
/**
* Remove the transition references
*/
final MediaItem afterMediaItem = transition.getAfterMediaItem();
if (afterMediaItem != null) {
afterMediaItem.setEndTransition(null);
}
final MediaItem beforeMediaItem = transition.getBeforeMediaItem();
if (beforeMediaItem != null) {
beforeMediaItem.setBeginTransition(null);
}
mTransitions.remove(transition);
transition.invalidate();
computeTimelineDuration();
return transition;
}
Aggregations