VideoEditorFactory.java revision fdacc8be92cd36f712cfdb0fcf9b0e847f8eeb58
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; 22 23 24/** 25 * The VideoEditorFactory class must be used to instantiate VideoEditor objects 26 * by creating a new project {@link #create(String)} or by loading an 27 * existing project {@link #load(String)}. 28 * {@hide} 29 */ 30public class VideoEditorFactory { 31 /** 32 * This is the factory method for creating a new VideoEditor instance. 33 * 34 * @param projectPath The path where all VideoEditor internal 35 * files are stored. When a project is deleted the application is 36 * responsible for deleting the path and its contents. 37 * 38 * @return The VideoEditor instance 39 * 40 * @throws IOException if path does not exist or if the path can 41 * not be accessed in read/write mode 42 * @throws IllegalStateException if a previous VideoEditor instance has not 43 * been released 44 */ 45 public static VideoEditor create(String projectPath) throws IOException { 46 // If the project path does not exist create it 47 final File dir = new File(projectPath); 48 if (!dir.exists()) { 49 if (!dir.mkdirs()) { 50 throw new FileNotFoundException("Cannot create project path: " + projectPath); 51 } 52 } 53 return new VideoEditorTestImpl(projectPath); 54 } 55 56 /** 57 * This is the factory method for instantiating a VideoEditor from the 58 * internal state previously saved with the 59 * {@link VideoEditor#save(String)} method. 60 * 61 * @param projectPath The path where all VideoEditor internal files 62 * are stored. When a project is deleted the application is 63 * responsible for deleting the path and its contents. 64 * @param generatePreview if set to true the 65 * {@link MediaEditor#generatePreview()} will be called internally to 66 * generate any needed transitions. 67 * 68 * @return The VideoEditor instance 69 * 70 * @throws IOException if path does not exist or if the path can 71 * not be accessed in read/write mode or if one of the resource 72 * media files cannot be retrieved 73 * @throws IllegalStateException if a previous VideoEditor instance has not 74 * been released 75 */ 76 public static VideoEditor load(String projectPath, boolean generatePreview) throws IOException { 77 final VideoEditorTestImpl videoEditor = new VideoEditorTestImpl(projectPath); 78 if (generatePreview) { 79 videoEditor.generatePreview(); 80 } 81 return videoEditor; 82 } 83} 84