summaryrefslogtreecommitdiffstats
path: root/media/java/android
diff options
context:
space:
mode:
authorGil Dobjanschi <virgild@google.com>2010-10-04 17:20:43 -0700
committerGil Dobjanschi <virgild@google.com>2010-10-04 17:20:43 -0700
commit3398abafca25ff8c58feedd4d2b82857a3322061 (patch)
treeba3965ad1b8c5c8d1bc1bb1b3f064476c9f97482 /media/java/android
parente799720dd478c60ac027d296f329b469119d1c1c (diff)
downloadframeworks_base-3398abafca25ff8c58feedd4d2b82857a3322061.zip
frameworks_base-3398abafca25ff8c58feedd4d2b82857a3322061.tar.gz
frameworks_base-3398abafca25ff8c58feedd4d2b82857a3322061.tar.bz2
Save AudioTrack to XML
Change-Id: Ie9afe8c620e21e160b56c36f489870db0a3987cc
Diffstat (limited to 'media/java/android')
-rwxr-xr-xmedia/java/android/media/videoeditor/AudioTrack.java46
-rwxr-xr-xmedia/java/android/media/videoeditor/MediaVideoItem.java3
-rwxr-xr-xmedia/java/android/media/videoeditor/VideoEditorFactory.java22
-rw-r--r--media/java/android/media/videoeditor/VideoEditorTestImpl.java56
4 files changed, 117 insertions, 10 deletions
diff --git a/media/java/android/media/videoeditor/AudioTrack.java b/media/java/android/media/videoeditor/AudioTrack.java
index 96d55f1..3b800f2 100755
--- a/media/java/android/media/videoeditor/AudioTrack.java
+++ b/media/java/android/media/videoeditor/AudioTrack.java
@@ -187,7 +187,7 @@ public class AudioTrack {
/**
* Constructor
- * @param audioTrackId The AudioTrack id
+ * @param audioTrackId The audio track id
* @param filename The absolute file name
*
* @throws IOException if file is not found
@@ -227,6 +227,50 @@ public class AudioTrack {
}
/**
+ * Constructor
+ *
+ * @param audioTrackId The audio track id
+ * @param filename The audio filename
+ * @param startTimeMs the start time in milliseconds (relative to the
+ * timeline)
+ * @param beginMs start time in the audio track in milliseconds (relative to
+ * the beginning of the audio track)
+ * @param endMs end time in the audio track in milliseconds (relative to the
+ * beginning of the audio track)
+ * @param loop true to loop the audio track
+ * @param volume The volume in percentage
+ * @param audioWaveformFilename The name of the waveform file
+ *
+ * @throws IOException if file is not found
+ */
+ AudioTrack(String audioTrackId, String filename, long startTimeMs, long beginMs, long endMs,
+ boolean loop, int volume, String audioWaveformFilename) throws IOException {
+ mUniqueId = audioTrackId;
+ mFilename = filename;
+ mStartTimeMs = startTimeMs;
+
+ // TODO: This value represents to the duration of the audio file
+ mDurationMs = 300000;
+
+ // TODO: This value needs to be read from the audio track of the source
+ // file
+ mAudioChannels = 2;
+ mAudioType = MediaProperties.ACODEC_AAC_LC;
+ mAudioBitrate = 128000;
+ mAudioSamplingFrequency = 44100;
+
+ mTimelineDurationMs = endMs - beginMs;
+ mVolumePercent = volume;
+
+ mBeginBoundaryTimeMs = beginMs;
+ mEndBoundaryTimeMs = endMs;
+
+ mLoop = loop;
+
+ mAudioWaveformFilename = audioWaveformFilename;
+ }
+
+ /**
* @return The id of the audio track
*/
public String getId() {
diff --git a/media/java/android/media/videoeditor/MediaVideoItem.java b/media/java/android/media/videoeditor/MediaVideoItem.java
index 47d4fa0..13014a7 100755
--- a/media/java/android/media/videoeditor/MediaVideoItem.java
+++ b/media/java/android/media/videoeditor/MediaVideoItem.java
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.List;
import android.graphics.Bitmap;
-import android.media.MediaRecorder;
import android.util.Log;
import android.view.SurfaceHolder;
@@ -228,7 +227,7 @@ public class MediaVideoItem extends MediaItem {
mHeight = 720;
mAspectRatio = MediaProperties.ASPECT_RATIO_3_2;
mFileType = MediaProperties.FILE_MP4;
- mVideoType = MediaRecorder.VideoEncoder.H264;
+ mVideoType = MediaProperties.VCODEC_H264BP;
// Do we have predefined values for this variable?
mVideoProfile = 0;
// Can video and audio duration be different?
diff --git a/media/java/android/media/videoeditor/VideoEditorFactory.java b/media/java/android/media/videoeditor/VideoEditorFactory.java
index 8081d76..0a377e2 100755
--- a/media/java/android/media/videoeditor/VideoEditorFactory.java
+++ b/media/java/android/media/videoeditor/VideoEditorFactory.java
@@ -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();
}
diff --git a/media/java/android/media/videoeditor/VideoEditorTestImpl.java b/media/java/android/media/videoeditor/VideoEditorTestImpl.java
index eb641db..de962e8 100644
--- a/media/java/android/media/videoeditor/VideoEditorTestImpl.java
+++ b/media/java/android/media/videoeditor/VideoEditorTestImpl.java
@@ -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) {
}