Search in sources :

Example 31 with MediaItem

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

the class VideoEditorImpl method addTransition.

/*
     * {@inheritDoc}
     */
public synchronized void addTransition(Transition transition) {
    if (transition == null) {
        throw new IllegalArgumentException("Null Transition");
    }
    final MediaItem beforeMediaItem = transition.getBeforeMediaItem();
    final MediaItem afterMediaItem = transition.getAfterMediaItem();
    /*
         * Check if the MediaItems are in sequence
         */
    if (mMediaItems == null) {
        throw new IllegalArgumentException("No media items are added");
    }
    if ((afterMediaItem != null) && (beforeMediaItem != null)) {
        final int afterMediaItemIndex = mMediaItems.indexOf(afterMediaItem);
        final int beforeMediaItemIndex = mMediaItems.indexOf(beforeMediaItem);
        if ((afterMediaItemIndex == -1) || (beforeMediaItemIndex == -1)) {
            throw new IllegalArgumentException("Either of the mediaItem is not found in the list");
        }
        if (afterMediaItemIndex != (beforeMediaItemIndex - 1)) {
            throw new IllegalArgumentException("MediaItems are not in sequence");
        }
    }
    mMANativeHelper.setGeneratePreview(true);
    mTransitions.add(transition);
    /*
         *  Cross reference the transitions
         */
    if (afterMediaItem != null) {
        /*
             *  If a transition already exists at the specified position then
             *  invalidate it.
             */
        if (afterMediaItem.getEndTransition() != null) {
            afterMediaItem.getEndTransition().invalidate();
            mTransitions.remove(afterMediaItem.getEndTransition());
        }
        afterMediaItem.setEndTransition(transition);
    }
    if (beforeMediaItem != null) {
        /*
             *  If a transition already exists at the specified position then
             *  invalidate it.
             */
        if (beforeMediaItem.getBeginTransition() != null) {
            beforeMediaItem.getBeginTransition().invalidate();
            mTransitions.remove(beforeMediaItem.getBeginTransition());
        }
        beforeMediaItem.setBeginTransition(transition);
    }
    computeTimelineDuration();
}
Also used : MediaItem(android.media.videoeditor.MediaItem)

Example 32 with MediaItem

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

the class VideoEditorImpl method computeTimelineDuration.

/**
     * Compute the duration
     */
private void computeTimelineDuration() {
    mDurationMs = 0;
    final int mediaItemsCount = mMediaItems.size();
    for (int i = 0; i < mediaItemsCount; i++) {
        final MediaItem mediaItem = mMediaItems.get(i);
        mDurationMs += mediaItem.getTimelineDuration();
        if (mediaItem.getEndTransition() != null) {
            if (i < mediaItemsCount - 1) {
                mDurationMs -= mediaItem.getEndTransition().getDuration();
            }
        }
    }
}
Also used : MediaItem(android.media.videoeditor.MediaItem)

Example 33 with MediaItem

use of android.media.videoeditor.MediaItem in project XobotOS by xamarin.

the class VideoEditorImpl method removeTransitionBefore.

/**
     * Remove the transition before this media item
     *
     * @param index The media item index
     */
private void removeTransitionBefore(int index) {
    final MediaItem mediaItem = mMediaItems.get(index);
    final Iterator<Transition> it = mTransitions.iterator();
    while (it.hasNext()) {
        Transition t = it.next();
        if (t.getBeforeMediaItem() == mediaItem) {
            mMANativeHelper.setGeneratePreview(true);
            it.remove();
            t.invalidate();
            mediaItem.setBeginTransition(null);
            if (index > 0) {
                mMediaItems.get(index - 1).setEndTransition(null);
            }
            break;
        }
    }
}
Also used : MediaItem(android.media.videoeditor.MediaItem)

Example 34 with MediaItem

use of android.media.videoeditor.MediaItem in project XobotOS by xamarin.

the class VideoEditorImpl method parseMediaItem.

/**
     * Parse the media item
     *
     * @param parser The parser
     * @return The media item
     */
private MediaItem parseMediaItem(XmlPullParser parser) throws IOException {
    final String mediaItemId = parser.getAttributeValue("", ATTR_ID);
    final String type = parser.getAttributeValue("", ATTR_TYPE);
    final String filename = parser.getAttributeValue("", ATTR_FILENAME);
    final int renderingMode = Integer.parseInt(parser.getAttributeValue("", ATTR_RENDERING_MODE));
    final MediaItem currentMediaItem;
    if (MediaImageItem.class.getSimpleName().equals(type)) {
        final long durationMs = Long.parseLong(parser.getAttributeValue("", ATTR_DURATION));
        currentMediaItem = new MediaImageItem(this, mediaItemId, filename, durationMs, renderingMode);
    } else if (MediaVideoItem.class.getSimpleName().equals(type)) {
        final long beginMs = Long.parseLong(parser.getAttributeValue("", ATTR_BEGIN_TIME));
        final long endMs = Long.parseLong(parser.getAttributeValue("", ATTR_END_TIME));
        final int volume = Integer.parseInt(parser.getAttributeValue("", ATTR_VOLUME));
        final boolean muted = Boolean.parseBoolean(parser.getAttributeValue("", ATTR_MUTED));
        final String audioWaveformFilename = parser.getAttributeValue("", ATTR_AUDIO_WAVEFORM_FILENAME);
        currentMediaItem = new MediaVideoItem(this, mediaItemId, filename, renderingMode, beginMs, endMs, volume, muted, audioWaveformFilename);
        final long beginTimeMs = Long.parseLong(parser.getAttributeValue("", ATTR_BEGIN_TIME));
        final long endTimeMs = Long.parseLong(parser.getAttributeValue("", ATTR_END_TIME));
        ((MediaVideoItem) currentMediaItem).setExtractBoundaries(beginTimeMs, endTimeMs);
        final int volumePercent = Integer.parseInt(parser.getAttributeValue("", ATTR_VOLUME));
        ((MediaVideoItem) currentMediaItem).setVolume(volumePercent);
    } else {
        throw new IllegalArgumentException("Unknown media item type: " + type);
    }
    return currentMediaItem;
}
Also used : MediaItem(android.media.videoeditor.MediaItem) MediaImageItem(android.media.videoeditor.MediaImageItem)

Example 35 with MediaItem

use of android.media.videoeditor.MediaItem in project XobotOS by xamarin.

the class VideoEditorImpl method insertMediaItem.

/*
     * {@inheritDoc}
     */
public synchronized void insertMediaItem(MediaItem mediaItem, String afterMediaItemId) {
    if (mMediaItems.contains(mediaItem)) {
        throw new IllegalArgumentException("Media item already exists: " + mediaItem.getId());
    }
    if (afterMediaItemId == null) {
        mMANativeHelper.setGeneratePreview(true);
        if (mMediaItems.size() > 0) {
            /**
                 *  Invalidate the transition at the beginning of the timeline
                 */
            removeTransitionBefore(0);
        }
        mMediaItems.add(0, mediaItem);
        computeTimelineDuration();
        generateProjectThumbnail();
    } 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 the transition at this position
                     */
                removeTransitionAfter(i);
                /**
                     *  Insert the new media item
                     */
                mMediaItems.add(i + 1, mediaItem);
                computeTimelineDuration();
                return;
            }
        }
        throw new IllegalArgumentException("MediaItem not found: " + afterMediaItemId);
    }
}
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