use of android.media.videoeditor.TransitionCrossfade in project android_frameworks_base by ParanoidAndroid.
the class VideoEditorAPITest method testTransitionCrossFade.
/**
* To test Transition : CrossFade with all behavior
* SPEED_UP/SPEED_DOWN/LINEAR/MIDDLE_SLOW/MIDDLE_FAST
*/
@LargeTest
public void testTransitionCrossFade() throws Exception {
final String videoItemFilename1 = INPUT_FILE_PATH + "H264_BP_640x480_30fps_256kbps_1_17.mp4";
final String videoItemFilename2 = INPUT_FILE_PATH + "H263_profile0_176x144_15fps_128kbps_1_35.3gp";
final String imageItemFilename1 = INPUT_FILE_PATH + "IMG_1600x1200.jpg";
final String videoItemFilename3 = INPUT_FILE_PATH + "H264_BP_640x480_30fps_192kbps_1_5.mp4";
final String videoItemFilename4 = INPUT_FILE_PATH + "MPEG4_SP_640x480_15fps_256kbps_0_30.mp4";
final String videoItemFilename5 = INPUT_FILE_PATH + "H263_profile0_176x144_10fps_96kbps_0_25.3gp";
boolean flagForException = false;
final MediaVideoItem mediaVideoItem1 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m1", videoItemFilename1, MediaItem.RENDERING_MODE_BLACK_BORDER);
mediaVideoItem1.setExtractBoundaries(0, 15000);
mVideoEditor.addMediaItem(mediaVideoItem1);
final MediaVideoItem mediaVideoItem2 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m2", videoItemFilename2, MediaItem.RENDERING_MODE_BLACK_BORDER);
mediaVideoItem2.setExtractBoundaries(0, 15000);
mVideoEditor.addMediaItem(mediaVideoItem2);
final TransitionCrossfade transition1And2 = mVideoEditorHelper.createTCrossFade("transition1And2", mediaVideoItem1, mediaVideoItem2, 3000, Transition.BEHAVIOR_SPEED_UP);
mVideoEditor.addTransition(transition1And2);
assertTrue("Transition ID", transition1And2.getId().equals("transition1And2"));
assertEquals("Transtion After Media item", mediaVideoItem1, transition1And2.getAfterMediaItem());
assertEquals("Transtion Before Media item", mediaVideoItem2, transition1And2.getBeforeMediaItem());
assertEquals("Transtion Duration", 3000, transition1And2.getDuration());
assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_UP, transition1And2.getBehavior());
final MediaImageItem mediaImageItem3 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m3", imageItemFilename1, 15000, MediaItem.RENDERING_MODE_BLACK_BORDER);
mVideoEditor.addMediaItem(mediaImageItem3);
final TransitionCrossfade transition2And3 = mVideoEditorHelper.createTCrossFade("transition2And3", mediaVideoItem2, mediaImageItem3, 1000, Transition.BEHAVIOR_SPEED_DOWN);
mVideoEditor.addTransition(transition2And3);
assertTrue("Transition ID", transition2And3.getId().equals("transition2And3"));
assertEquals("Transtion After Media item", mediaVideoItem2, transition2And3.getAfterMediaItem());
assertEquals("Transtion Before Media item", mediaImageItem3, transition2And3.getBeforeMediaItem());
assertEquals("Transtion Duration", 1000, transition2And3.getDuration());
assertEquals("Transtion Behavior", Transition.BEHAVIOR_SPEED_DOWN, transition2And3.getBehavior());
final MediaVideoItem mediaVideoItem4 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m4", videoItemFilename3, MediaItem.RENDERING_MODE_BLACK_BORDER);
mediaVideoItem4.setExtractBoundaries(0, 18000);
mVideoEditor.addMediaItem(mediaVideoItem4);
final TransitionCrossfade transition3And4 = mVideoEditorHelper.createTCrossFade("transition3And4", mediaImageItem3, mediaVideoItem4, 5000, Transition.BEHAVIOR_LINEAR);
mVideoEditor.addTransition(transition3And4);
assertTrue("Transition ID", transition3And4.getId().equals("transition3And4"));
assertEquals("Transtion After Media item", mediaImageItem3, transition3And4.getAfterMediaItem());
assertEquals("Transtion Before Media item", mediaVideoItem4, transition3And4.getBeforeMediaItem());
assertEquals("Transtion Duration", 5000, transition3And4.getDuration());
assertEquals("Transtion Behavior", Transition.BEHAVIOR_LINEAR, transition3And4.getBehavior());
final MediaVideoItem mediaVideoItem5 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m5", videoItemFilename4, MediaItem.RENDERING_MODE_BLACK_BORDER);
mVideoEditor.addMediaItem(mediaVideoItem5);
final TransitionCrossfade transition4And5 = mVideoEditorHelper.createTCrossFade("transition4And5", mediaVideoItem4, mediaVideoItem5, 8000, Transition.BEHAVIOR_MIDDLE_FAST);
mVideoEditor.addTransition(transition4And5);
assertTrue("Transition ID", transition4And5.getId().equals("transition4And5"));
assertEquals("Transtion After Media item", mediaVideoItem4, transition4And5.getAfterMediaItem());
assertEquals("Transtion Before Media item", mediaVideoItem5, transition4And5.getBeforeMediaItem());
assertEquals("Transtion Duration", 8000, transition4And5.getDuration());
assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_FAST, transition4And5.getBehavior());
final MediaVideoItem mediaVideoItem6 = mVideoEditorHelper.createMediaItem(mVideoEditor, "m6", videoItemFilename5, MediaItem.RENDERING_MODE_BLACK_BORDER);
mediaVideoItem6.setExtractBoundaries(0, 20000);
mVideoEditor.addMediaItem(mediaVideoItem6);
final TransitionCrossfade transition5And6 = mVideoEditorHelper.createTCrossFade("transition5And6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_SLOW);
mVideoEditor.addTransition(transition5And6);
assertTrue("Transition ID", transition5And6.getId().equals("transition5And6"));
assertEquals("Transtion After Media item", mediaVideoItem5, transition5And6.getAfterMediaItem());
assertEquals("Transtion Before Media item", mediaVideoItem6, transition5And6.getBeforeMediaItem());
assertEquals("Transtion Duration", 2000, transition5And6.getDuration());
assertEquals("Transtion Behavior", Transition.BEHAVIOR_MIDDLE_SLOW, transition5And6.getBehavior());
flagForException = false;
try {
mVideoEditorHelper.createTCrossFade("transitiond6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_SPEED_UP - 1);
} catch (IllegalArgumentException e) {
flagForException = true;
}
assertTrue("Transition FadeBlack with Invalid behavior", flagForException);
flagForException = false;
try {
mVideoEditorHelper.createTCrossFade("transitiond6", mediaVideoItem5, mediaVideoItem6, 2000, Transition.BEHAVIOR_MIDDLE_FAST + 1);
} catch (IllegalArgumentException e) {
flagForException = true;
}
assertTrue("Transition FadeBlack with Invalid behavior", flagForException);
}
Aggregations