Search in sources :

Example 16 with MediaItem

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;
}
Also used : MediaItem(android.media.videoeditor.MediaItem) MediaImageItem(android.media.videoeditor.MediaImageItem)

Example 17 with 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;
}
Also used : MediaItem(android.media.videoeditor.MediaItem)

Example 18 with 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;
        }
    }
}
Also used : MediaItem(android.media.videoeditor.MediaItem)

Example 19 with MediaItem

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;
}
Also used : MediaItem(android.media.videoeditor.MediaItem) File(java.io.File)

Example 20 with MediaItem

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;
}
Also used : MediaItem(android.media.videoeditor.MediaItem)

Aggregations

MediaItem (android.media.videoeditor.MediaItem)35 MediaImageItem (android.media.videoeditor.MediaImageItem)11 File (java.io.File)8 MediaVideoItem (android.media.videoeditor.MediaVideoItem)5 LargeTest (android.test.suitebuilder.annotation.LargeTest)5 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 Bitmap (android.graphics.Bitmap)3 TransitionCrossfade (android.media.videoeditor.TransitionCrossfade)3 Rect (android.graphics.Rect)2 MediaMetadataRetriever (android.media.MediaMetadataRetriever)2 AudioTrack (android.media.videoeditor.AudioTrack)2 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 XmlPullParser (org.xmlpull.v1.XmlPullParser)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 XmlSerializer (org.xmlpull.v1.XmlSerializer)2