OSDN Git Service

Save AudioTrack to XML
authorGil Dobjanschi <virgild@google.com>
Tue, 5 Oct 2010 00:20:43 +0000 (17:20 -0700)
committerGil Dobjanschi <virgild@google.com>
Tue, 5 Oct 2010 00:20:43 +0000 (17:20 -0700)
Change-Id: Ie9afe8c620e21e160b56c36f489870db0a3987cc

media/java/android/media/videoeditor/AudioTrack.java
media/java/android/media/videoeditor/MediaVideoItem.java
media/java/android/media/videoeditor/VideoEditorFactory.java
media/java/android/media/videoeditor/VideoEditorTestImpl.java

index 96d55f1..3b800f2 100755 (executable)
@@ -187,7 +187,7 @@ public class AudioTrack {
 \r
     /**\r
      * Constructor\r
-     * @param audioTrackId The AudioTrack id\r
+     * @param audioTrackId The audio track id\r
      * @param filename The absolute file name\r
      *\r
      * @throws IOException if file is not found\r
@@ -227,6 +227,50 @@ public class AudioTrack {
     }\r
 \r
     /**\r
+     * Constructor\r
+     *\r
+     * @param audioTrackId The audio track id\r
+     * @param filename The audio filename\r
+     * @param startTimeMs the start time in milliseconds (relative to the\r
+     *              timeline)\r
+     * @param beginMs start time in the audio track in milliseconds (relative to\r
+     *            the beginning of the audio track)\r
+     * @param endMs end time in the audio track in milliseconds (relative to the\r
+     *            beginning of the audio track)\r
+     * @param loop true to loop the audio track\r
+     * @param volume The volume in percentage\r
+     * @param audioWaveformFilename The name of the waveform file\r
+     *\r
+     * @throws IOException if file is not found\r
+     */\r
+    AudioTrack(String audioTrackId, String filename, long startTimeMs, long beginMs, long endMs,\r
+            boolean loop, int volume, String audioWaveformFilename) throws IOException {\r
+        mUniqueId = audioTrackId;\r
+        mFilename = filename;\r
+        mStartTimeMs = startTimeMs;\r
+\r
+        // TODO: This value represents to the duration of the audio file\r
+        mDurationMs = 300000;\r
+\r
+        // TODO: This value needs to be read from the audio track of the source\r
+        // file\r
+        mAudioChannels = 2;\r
+        mAudioType = MediaProperties.ACODEC_AAC_LC;\r
+        mAudioBitrate = 128000;\r
+        mAudioSamplingFrequency = 44100;\r
+\r
+        mTimelineDurationMs = endMs - beginMs;\r
+        mVolumePercent = volume;\r
+\r
+        mBeginBoundaryTimeMs = beginMs;\r
+        mEndBoundaryTimeMs = endMs;\r
+\r
+        mLoop = loop;\r
+\r
+        mAudioWaveformFilename = audioWaveformFilename;\r
+    }\r
+\r
+    /**\r
      * @return The id of the audio track\r
      */\r
     public String getId() {\r
index 47d4fa0..13014a7 100755 (executable)
@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.util.List;\r
 \r
 import android.graphics.Bitmap;\r
-import android.media.MediaRecorder;\r
 import android.util.Log;\r
 import android.view.SurfaceHolder;\r
 \r
@@ -228,7 +227,7 @@ public class MediaVideoItem extends MediaItem {
         mHeight = 720;\r
         mAspectRatio = MediaProperties.ASPECT_RATIO_3_2;\r
         mFileType = MediaProperties.FILE_MP4;\r
-        mVideoType = MediaRecorder.VideoEncoder.H264;\r
+        mVideoType = MediaProperties.VCODEC_H264BP;\r
         // Do we have predefined values for this variable?\r
         mVideoProfile = 0;\r
         // Can video and audio duration be different?\r
index 8081d76..0a377e2 100755 (executable)
@@ -66,11 +66,11 @@ public class VideoEditorFactory {
             }
         }
 
-        Class<?> cls = Class.forName(className);
-        Class<?> partypes[] = new Class[1];
+        final Class<?> cls = Class.forName(className);
+        final Class<?> partypes[] = new Class[1];
         partypes[0] = String.class;
-        Constructor<?> ct = cls.getConstructor(partypes);
-        Object arglist[] = new Object[1];
+        final Constructor<?> ct = cls.getConstructor(partypes);
+        final Object arglist[] = new Object[1];
         arglist[0] = projectPath;
 
         return (VideoEditor)ct.newInstance(arglist);
@@ -84,6 +84,7 @@ public class VideoEditorFactory {
      * @param projectPath The path where all VideoEditor internal files
      *            are stored. When a project is deleted the application is
      *            responsible for deleting the path and its contents.
+     * @param className The implementation class name
      * @param generatePreview if set to true the
      *      {@link MediaEditor#generatePreview()} will be called internally to
      *      generate any needed transitions.
@@ -96,8 +97,17 @@ public class VideoEditorFactory {
      * @throws IllegalStateException if a previous VideoEditor instance has not
      *             been released
      */
-    public static VideoEditor load(String projectPath, boolean generatePreview) throws IOException {
-        final VideoEditorTestImpl videoEditor = new VideoEditorTestImpl(projectPath);
+    public static VideoEditor load(String projectPath, String className, boolean generatePreview)
+            throws IOException, ClassNotFoundException, NoSuchMethodException,
+            InvocationTargetException, IllegalAccessException, InstantiationException {
+        final Class<?> cls = Class.forName(className);
+        final Class<?> partypes[] = new Class[1];
+        partypes[0] = String.class;
+        final Constructor<?> ct = cls.getConstructor(partypes);
+        final Object arglist[] = new Object[1];
+        arglist[0] = projectPath;
+
+        final VideoEditor videoEditor = (VideoEditor)ct.newInstance(arglist);
         if (generatePreview) {
             videoEditor.generatePreview();
         }
index eb641db..de962e8 100644 (file)
@@ -57,6 +57,8 @@ public class VideoEditorTestImpl implements VideoEditor {
     private static final String TAG_OVERLAY_USER_ATTRIBUTES = "overlay_user_attributes";
     private static final String TAG_EFFECTS = "effects";
     private static final String TAG_EFFECT = "effect";
+    private static final String TAG_AUDIO_TRACKS = "audio_tracks";
+    private static final String TAG_AUDIO_TRACK = "audio_track";
 
     private static final String ATTR_ID = "id";
     private static final String ATTR_FILENAME = "filename";
@@ -65,7 +67,8 @@ public class VideoEditorTestImpl implements VideoEditor {
     private static final String ATTR_ASPECT_RATIO = "aspect_ratio";
     private static final String ATTR_TYPE = "type";
     private static final String ATTR_DURATION = "duration";
-    private static final String ATTR_BEGIN_TIME = "start_time";
+    private static final String ATTR_START_TIME = "start_time";
+    private static final String ATTR_BEGIN_TIME = "begin_time";
     private static final String ATTR_END_TIME = "end_time";
     private static final String ATTR_VOLUME = "volume";
     private static final String ATTR_BEHAVIOR = "behavior";
@@ -85,6 +88,7 @@ public class VideoEditorTestImpl implements VideoEditor {
     private static final String ATTR_END_RECT_T = "end_t";
     private static final String ATTR_END_RECT_R = "end_r";
     private static final String ATTR_END_RECT_B = "end_b";
+    private static final String ATTR_LOOP = "loop";
 
     // Instance variables
     private long mDurationMs;
@@ -700,6 +704,25 @@ public class VideoEditorTestImpl implements VideoEditor {
         }
         serializer.endTag("", TAG_TRANSITIONS);
 
+        serializer.startTag("", TAG_AUDIO_TRACKS);
+        for (AudioTrack at : mAudioTracks) {
+            serializer.startTag("", TAG_AUDIO_TRACK);
+            serializer.attribute("", ATTR_ID, at.getId());
+            serializer.attribute("", ATTR_FILENAME, at.getFilename());
+            serializer.attribute("", ATTR_START_TIME, Long.toString(at.getStartTime()));
+            serializer.attribute("", ATTR_BEGIN_TIME, Long.toString(at.getBoundaryBeginTime()));
+            serializer.attribute("", ATTR_END_TIME, Long.toString(at.getBoundaryEndTime()));
+            serializer.attribute("", ATTR_VOLUME, Integer.toString(at.getVolume()));
+            serializer.attribute("", ATTR_LOOP, Boolean.toString(at.isLooping()));
+            if (at.getAudioWaveformFilename() != null) {
+                serializer.attribute("", ATTR_AUDIO_WAVEFORM_FILENAME,
+                at.getAudioWaveformFilename());
+            }
+
+            serializer.endTag("", TAG_AUDIO_TRACK);
+        }
+        serializer.endTag("", TAG_AUDIO_TRACKS);
+
         serializer.endTag("", TAG_PROJECT);
         serializer.endDocument();
 
@@ -792,6 +815,11 @@ public class VideoEditorTestImpl implements VideoEditor {
                                 currentMediaItem.addEffect(effect);
                             }
                         }
+                    } else if (TAG_AUDIO_TRACK.equals(name)) {
+                        final AudioTrack audioTrack = parseAudioTrack(parser);
+                        if (audioTrack != null) {
+                            addAudioTrack(audioTrack);
+                        }
                     }
                     break;
                 }
@@ -959,6 +987,32 @@ public class VideoEditorTestImpl implements VideoEditor {
         return effect;
     }
 
+    /**
+     * Parse the audio track
+     *
+     * @param parser The parser
+     *
+     * @return The audio track
+     */
+    private AudioTrack parseAudioTrack(XmlPullParser parser) {
+        final String audioTrackId = parser.getAttributeValue("", ATTR_ID);
+        final String filename = parser.getAttributeValue("", ATTR_FILENAME);
+        final long startTimeMs = Long.parseLong(parser.getAttributeValue("", ATTR_START_TIME));
+        final long beginMs = Long.parseLong(parser.getAttributeValue("", ATTR_BEGIN_TIME));
+        final long endMs = Long.parseLong(parser.getAttributeValue("", ATTR_END_TIME));
+        final int volume = Integer.parseInt(parser.getAttributeValue("", ATTR_VOLUME));
+        final boolean loop = Boolean.parseBoolean(parser.getAttributeValue("", ATTR_LOOP));
+        final String waveformFilename = parser.getAttributeValue("", ATTR_AUDIO_WAVEFORM_FILENAME);
+        try {
+            final AudioTrack audioTrack = new AudioTrack(audioTrackId, filename, startTimeMs,
+                    beginMs, endMs, loop, volume, waveformFilename);
+
+            return audioTrack;
+        } catch (IOException ex) {
+            return null;
+        }
+    }
+
     public void cancelExport(String filename) {
     }