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 17 18package android.media.videoeditor; 19 20import java.io.File; 21import java.io.FileNotFoundException; 22import java.io.IOException; 23 24import android.media.videoeditor.VideoEditor.MediaProcessingProgressListener; 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 /** 34 * This is the factory method for creating a new VideoEditor instance. 35 * 36 * @param projectPath The path where all VideoEditor internal 37 * files are stored. When a project is deleted the application is 38 * responsible for deleting the path and its contents. 39 * 40 * @return The VideoEditor instance 41 * 42 * @throws IOException if path does not exist or if the path can 43 * not be accessed in read/write mode 44 */ 45 public static VideoEditor create(String projectPath) throws IOException { 46 /* 47 * If the project path does not exist create it 48 */ 49 final File dir = new File(projectPath); 50 if (!dir.exists()) { 51 if (!dir.mkdirs()) { 52 throw new FileNotFoundException("Cannot create project path: " 53 + projectPath); 54 } else { 55 /* 56 * Create the file which hides the media files 57 * from the media scanner 58 */ 59 if (!new File(dir, ".nomedia").createNewFile()) { 60 throw new FileNotFoundException("Cannot create file .nomedia"); 61 } 62 } 63 } 64 65 return new VideoEditorImpl(projectPath); 66 } 67 68 /** 69 * This is the factory method for instantiating a VideoEditor from the 70 * internal state previously saved with the 71 * {@link VideoEditor#save(String)} method. 72 * 73 * @param projectPath The path where all VideoEditor internal files 74 * are stored. When a project is deleted the application is 75 * responsible for deleting the path and its contents. 76 * @param generatePreview if set to true the 77 * {@link MediaEditor#generatePreview(MediaProcessingProgressListener 78 * listener)} 79 * will be called internally to generate any needed transitions. 80 * 81 * @return The VideoEditor instance 82 * 83 * @throws IOException if path does not exist or if the path can 84 * not be accessed in read/write mode or if one of the resource 85 * media files cannot be retrieved 86 */ 87 public static VideoEditor load(String projectPath, boolean generatePreview) 88 throws IOException { 89 final VideoEditor videoEditor = new VideoEditorImpl(projectPath); 90 if (generatePreview) { 91 videoEditor.generatePreview(null); 92 } 93 return videoEditor; 94 } 95} 96