VideoEditorFactory.java revision 3398abafca25ff8c58feedd4d2b82857a3322061
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.media.videoeditor; 18 19import java.io.File; 20import java.io.FileNotFoundException; 21import java.io.IOException; 22import java.lang.reflect.Constructor; 23import java.lang.reflect.InvocationTargetException; 24 25 26/** 27 * The VideoEditorFactory class must be used to instantiate VideoEditor objects 28 * by creating a new project {@link #create(String)} or by loading an 29 * existing project {@link #load(String)}. 30 * {@hide} 31 */ 32public class VideoEditorFactory { 33 // VideoEditor implementation classes 34 public static final String TEST_CLASS_IMPLEMENTATION 35 = "android.media.videoeditor.VideoEditorTestImpl"; 36 public static final String DEFAULT_CLASS_IMPLEMENTATION 37 = "android.media.videoeditor.VideoEditorImpl"; 38 39 /** 40 * This is the factory method for creating a new VideoEditor instance. 41 * 42 * @param projectPath The path where all VideoEditor internal 43 * files are stored. When a project is deleted the application is 44 * responsible for deleting the path and its contents. 45 * @param className The implementation class name 46 * 47 * @return The VideoEditor instance 48 * 49 * @throws IOException if path does not exist or if the path can 50 * not be accessed in read/write mode 51 * @throws IllegalStateException if a previous VideoEditor instance has not 52 * been released 53 * @throws ClassNotFoundException, NoSuchMethodException, 54 * InvocationTargetException, IllegalAccessException, 55 * InstantiationException if the implementation class cannot 56 * be instantiated. 57 */ 58 public static VideoEditor create(String projectPath, String className) throws IOException, 59 ClassNotFoundException, NoSuchMethodException, InvocationTargetException, 60 IllegalAccessException, InstantiationException { 61 // If the project path does not exist create it 62 final File dir = new File(projectPath); 63 if (!dir.exists()) { 64 if (!dir.mkdirs()) { 65 throw new FileNotFoundException("Cannot create project path: " + projectPath); 66 } 67 } 68 69 final Class<?> cls = Class.forName(className); 70 final Class<?> partypes[] = new Class[1]; 71 partypes[0] = String.class; 72 final Constructor<?> ct = cls.getConstructor(partypes); 73 final Object arglist[] = new Object[1]; 74 arglist[0] = projectPath; 75 76 return (VideoEditor)ct.newInstance(arglist); 77 } 78 79 /** 80 * This is the factory method for instantiating a VideoEditor from the 81 * internal state previously saved with the 82 * {@link VideoEditor#save(String)} method. 83 * 84 * @param projectPath The path where all VideoEditor internal files 85 * are stored. When a project is deleted the application is 86 * responsible for deleting the path and its contents. 87 * @param className The implementation class name 88 * @param generatePreview if set to true the 89 * {@link MediaEditor#generatePreview()} will be called internally to 90 * generate any needed transitions. 91 * 92 * @return The VideoEditor instance 93 * 94 * @throws IOException if path does not exist or if the path can 95 * not be accessed in read/write mode or if one of the resource 96 * media files cannot be retrieved 97 * @throws IllegalStateException if a previous VideoEditor instance has not 98 * been released 99 */ 100 public static VideoEditor load(String projectPath, String className, boolean generatePreview) 101 throws IOException, ClassNotFoundException, NoSuchMethodException, 102 InvocationTargetException, IllegalAccessException, InstantiationException { 103 final Class<?> cls = Class.forName(className); 104 final Class<?> partypes[] = new Class[1]; 105 partypes[0] = String.class; 106 final Constructor<?> ct = cls.getConstructor(partypes); 107 final Object arglist[] = new Object[1]; 108 arglist[0] = projectPath; 109 110 final VideoEditor videoEditor = (VideoEditor)ct.newInstance(arglist); 111 if (generatePreview) { 112 videoEditor.generatePreview(); 113 } 114 return videoEditor; 115 } 116} 117