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();
}
}
}
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);
}
}
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();
}
}
}
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;
}
Aggregations