Search in sources :

Example 1 with MediaItem

use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorImpl method setAspectRatio.

/*
     * {@inheritDoc}
     */
public void setAspectRatio(int aspectRatio) {
    mAspectRatio = aspectRatio;
    /**
         *  Invalidate all transitions
         */
    mMANativeHelper.setGeneratePreview(true);
    for (Transition transition : mTransitions) {
        transition.invalidate();
    }
    final Iterator<MediaItem> it = mMediaItems.iterator();
    while (it.hasNext()) {
        final MediaItem t = it.next();
        List<Overlay> overlayList = t.getAllOverlays();
        for (Overlay overlay : overlayList) {
            ((OverlayFrame) overlay).invalidateGeneratedFiles();
        }
    }
}
Also used : MediaItem(android.media.videoeditor.MediaItem)

Example 2 with MediaItem

use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorImpl method moveMediaItem.

/*
     * {@inheritDoc}
     */
public synchronized void moveMediaItem(String mediaItemId, String afterMediaItemId) {
    final MediaItem moveMediaItem = removeMediaItem(mediaItemId, true);
    if (moveMediaItem == null) {
        throw new IllegalArgumentException("Target MediaItem not found: " + mediaItemId);
    }
    if (afterMediaItemId == null) {
        if (mMediaItems.size() > 0) {
            mMANativeHelper.setGeneratePreview(true);
            /**
                 *  Invalidate adjacent transitions at the insertion point
                 */
            removeTransitionBefore(0);
            /**
                 *  Insert the media item at the new position
                 */
            mMediaItems.add(0, moveMediaItem);
            computeTimelineDuration();
            generateProjectThumbnail();
        } else {
            throw new IllegalStateException("Cannot move media item (it is the only item)");
        }
    } else {
        final int mediaItemCount = mMediaItems.size();
        for (int i = 0; i < mediaItemCount; i++) {
            final MediaItem mi = mMediaItems.get(i);
            if (mi.getId().equals(afterMediaItemId)) {
                mMANativeHelper.setGeneratePreview(true);
                /**
                     *  Invalidate adjacent transitions at the insertion point
                     */
                removeTransitionAfter(i);
                /**
                     *  Insert the media item at the new position
                     */
                mMediaItems.add(i + 1, moveMediaItem);
                computeTimelineDuration();
                return;
            }
        }
        throw new IllegalArgumentException("MediaItem not found: " + afterMediaItemId);
    }
}
Also used : MediaItem(android.media.videoeditor.MediaItem)

Example 3 with MediaItem

use of android.media.videoeditor.MediaItem in project android_frameworks_base by ParanoidAndroid.

the class VideoEditorImpl method load.

/**
     *  the project form XML
     */
private void load() throws FileNotFoundException, XmlPullParserException, IOException {
    final File file = new File(mProjectPath, PROJECT_FILENAME);
    /**
         *  Load the metadata
         */
    final FileInputStream fis = new FileInputStream(file);
    try {
        final List<String> ignoredMediaItems = new ArrayList<String>();
        final XmlPullParser parser = Xml.newPullParser();
        parser.setInput(fis, "UTF-8");
        int eventType = parser.getEventType();
        String name;
        MediaItem currentMediaItem = null;
        Overlay currentOverlay = null;
        boolean regenerateProjectThumbnail = false;
        while (eventType != XmlPullParser.END_DOCUMENT) {
            switch(eventType) {
                case XmlPullParser.START_TAG:
                    {
                        name = parser.getName();
                        if (TAG_PROJECT.equals(name)) {
                            mAspectRatio = Integer.parseInt(parser.getAttributeValue("", ATTR_ASPECT_RATIO));
                            final boolean mRegenPCM = Boolean.parseBoolean(parser.getAttributeValue("", ATTR_REGENERATE_PCM));
                            mMANativeHelper.setAudioflag(mRegenPCM);
                        } else if (TAG_MEDIA_ITEM.equals(name)) {
                            final String mediaItemId = parser.getAttributeValue("", ATTR_ID);
                            try {
                                currentMediaItem = parseMediaItem(parser);
                                mMediaItems.add(currentMediaItem);
                            } catch (Exception ex) {
                                Log.w(TAG, "Cannot load media item: " + mediaItemId, ex);
                                currentMediaItem = null;
                                // First media item is invalid, mark for project thumbnail removal
                                if (mMediaItems.size() == 0) {
                                    regenerateProjectThumbnail = true;
                                }
                                // Ignore the media item
                                ignoredMediaItems.add(mediaItemId);
                            }
                        } else if (TAG_TRANSITION.equals(name)) {
                            try {
                                final Transition transition = parseTransition(parser, ignoredMediaItems);
                                // media items are ignored
                                if (transition != null) {
                                    mTransitions.add(transition);
                                }
                            } catch (Exception ex) {
                                Log.w(TAG, "Cannot load transition", ex);
                            }
                        } else if (TAG_OVERLAY.equals(name)) {
                            if (currentMediaItem != null) {
                                try {
                                    currentOverlay = parseOverlay(parser, currentMediaItem);
                                    currentMediaItem.addOverlay(currentOverlay);
                                } catch (Exception ex) {
                                    Log.w(TAG, "Cannot load overlay", ex);
                                }
                            }
                        } else if (TAG_OVERLAY_USER_ATTRIBUTES.equals(name)) {
                            if (currentOverlay != null) {
                                final int attributesCount = parser.getAttributeCount();
                                for (int i = 0; i < attributesCount; i++) {
                                    currentOverlay.setUserAttribute(parser.getAttributeName(i), parser.getAttributeValue(i));
                                }
                            }
                        } else if (TAG_EFFECT.equals(name)) {
                            if (currentMediaItem != null) {
                                try {
                                    final Effect effect = parseEffect(parser, currentMediaItem);
                                    currentMediaItem.addEffect(effect);
                                    if (effect instanceof EffectKenBurns) {
                                        final boolean isImageClipGenerated = Boolean.parseBoolean(parser.getAttributeValue("", ATTR_IS_IMAGE_CLIP_GENERATED));
                                        if (isImageClipGenerated) {
                                            final String filename = parser.getAttributeValue("", ATTR_GENERATED_IMAGE_CLIP);
                                            if (new File(filename).exists() == true) {
                                                ((MediaImageItem) currentMediaItem).setGeneratedImageClip(filename);
                                                ((MediaImageItem) currentMediaItem).setRegenerateClip(false);
                                            } else {
                                                ((MediaImageItem) currentMediaItem).setGeneratedImageClip(null);
                                                ((MediaImageItem) currentMediaItem).setRegenerateClip(true);
                                            }
                                        } else {
                                            ((MediaImageItem) currentMediaItem).setGeneratedImageClip(null);
                                            ((MediaImageItem) currentMediaItem).setRegenerateClip(true);
                                        }
                                    }
                                } catch (Exception ex) {
                                    Log.w(TAG, "Cannot load effect", ex);
                                }
                            }
                        } else if (TAG_AUDIO_TRACK.equals(name)) {
                            try {
                                final AudioTrack audioTrack = parseAudioTrack(parser);
                                addAudioTrack(audioTrack);
                            } catch (Exception ex) {
                                Log.w(TAG, "Cannot load audio track", ex);
                            }
                        }
                        break;
                    }
                case XmlPullParser.END_TAG:
                    {
                        name = parser.getName();
                        if (TAG_MEDIA_ITEM.equals(name)) {
                            currentMediaItem = null;
                        } else if (TAG_OVERLAY.equals(name)) {
                            currentOverlay = null;
                        }
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
            eventType = parser.next();
        }
        computeTimelineDuration();
        // Regenerate project thumbnail
        if (regenerateProjectThumbnail) {
            generateProjectThumbnail();
            regenerateProjectThumbnail = false;
        }
    } finally {
        if (fis != null) {
            fis.close();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) XmlPullParser(org.xmlpull.v1.XmlPullParser) MediaImageItem(android.media.videoeditor.MediaImageItem) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) MediaItem(android.media.videoeditor.MediaItem) File(java.io.File)

Example 4 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 5 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)

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