Merge "Remove MediaVideoItem and AudioTrack playback APIs."
diff --git a/media/java/android/media/videoeditor/AudioTrack.java b/media/java/android/media/videoeditor/AudioTrack.java
index 3ebad00..076cc31 100755
--- a/media/java/android/media/videoeditor/AudioTrack.java
+++ b/media/java/android/media/videoeditor/AudioTrack.java
@@ -18,17 +18,12 @@
 

 import java.io.IOException;

 

-import android.util.Log;

-

 /**

  * This class allows to handle an audio track. This audio file is mixed with the

  * audio samples of the MediaItems.

  * {@hide}

  */

 public class AudioTrack {

-    // Logging

-    private static final String TAG = "AudioTrack";

-

     // Instance variables

     private final String mUniqueId;

     private final String mFilename;

@@ -53,129 +48,6 @@
 

     // The audio waveform filename

     private String mAudioWaveformFilename;

-    private PlaybackThread mPlaybackThread;

-

-    /**

-     * This listener interface is used by the AudioTrack to emit playback

-     * progress notifications.

-     */

-    public interface PlaybackProgressListener {

-        /**

-         * This method notifies the listener of the current time position while

-         * playing an audio track

-         *

-         * @param audioTrack The audio track

-         * @param timeMs The current playback position (expressed in milliseconds

-         *            since the beginning of the audio track).

-         * @param end true if the end of the audio track was reached

-         */

-        public void onProgress(AudioTrack audioTrack, long timeMs, boolean end);

-    }

-

-    /**

-     * The playback thread

-     */

-    private class PlaybackThread extends Thread {

-        // Instance variables

-        private final PlaybackProgressListener mListener;

-        private final long mFromMs, mToMs;

-        private boolean mRun;

-        private final boolean mLoop;

-        private long mPositionMs;

-

-        /**

-         * Constructor

-         *

-         * @param fromMs The time (relative to the beginning of the audio track)

-         *            at which the playback will start

-         * @param toMs The time (relative to the beginning of the audio track) at

-         *            which the playback will stop. Use -1 to play to the end of

-         *            the audio track

-         * @param loop true if the playback should be looped once it reaches the

-         *            end

-         * @param listener The listener which will be notified of the playback

-         *            progress

-         */

-        public PlaybackThread(long fromMs, long toMs, boolean loop,

-                PlaybackProgressListener listener) {

-            mPositionMs = mFromMs = fromMs;

-            if (toMs < 0) {

-                mToMs = mDurationMs;

-            } else {

-                mToMs = toMs;

-            }

-            mLoop = loop;

-            mListener = listener;

-            mRun = true;

-        }

-

-        /*

-         * {@inheritDoc}

-         */

-        @Override

-        public void run() {

-            if (Log.isLoggable(TAG, Log.DEBUG)) {

-                Log.d(TAG, "===> PlaybackThread.run enter");

-            }

-

-            while (mRun) {

-                try {

-                    sleep(100);

-                } catch (InterruptedException ex) {

-                    break;

-                }

-

-                mPositionMs += 100;

-

-                if (mPositionMs >= mToMs) {

-                    if (!mLoop) {

-                        if (mListener != null) {

-                            mListener.onProgress(AudioTrack.this, mPositionMs, true);

-                        }

-                        if (Log.isLoggable(TAG, Log.DEBUG)) {

-                            Log.d(TAG, "PlaybackThread.run playback complete");

-                        }

-                        break;

-                    } else {

-                        // Fire a notification for the end of the clip

-                        if (mListener != null) {

-                            mListener.onProgress(AudioTrack.this, mToMs, false);

-                        }

-

-                        // Rewind

-                        mPositionMs = mFromMs;

-                        if (mListener != null) {

-                            mListener.onProgress(AudioTrack.this, mPositionMs, false);

-                        }

-                        if (Log.isLoggable(TAG, Log.DEBUG)) {

-                            Log.d(TAG, "PlaybackThread.run playback complete");

-                        }

-                    }

-                } else {

-                    if (mListener != null) {

-                        mListener.onProgress(AudioTrack.this, mPositionMs, false);

-                    }

-                }

-            }

-            if (Log.isLoggable(TAG, Log.DEBUG)) {

-                Log.d(TAG, "===> PlaybackThread.run exit");

-            }

-        }

-

-        /**

-         * Stop the playback

-         *

-         * @return The stop position

-         */

-        public long stopPlayback() {

-            mRun = false;

-            try {

-                join();

-            } catch (InterruptedException ex) {

-            }

-            return mPositionMs;

-        }

-    };

 

     /**

      * An object of this type cannot be instantiated by using the default

@@ -509,50 +381,6 @@
     }

 

     /**

-     * Start the playback of this audio track. This method does not block (does

-     * not wait for the playback to complete).

-     *

-     * @param fromMs The time (relative to the beginning of the audio track) at

-     *            which the playback will start

-     * @param toMs The time (relative to the beginning of the audio track) at

-     *            which the playback will stop. Use -1 to play to the end of the

-     *            audio track

-     * @param loop true if the playback should be looped once it reaches the end

-     * @param listener The listener which will be notified of the playback

-     *            progress

-     * @throws IllegalArgumentException if fromMs or toMs is beyond the playback

-     *             duration

-     * @throws IllegalStateException if a playback, preview or an export is

-     *             already in progress

-     */

-    public void startPlayback(long fromMs, long toMs, boolean loop,

-            PlaybackProgressListener listener) {

-        if (fromMs >= mDurationMs) {

-            return;

-        }

-        mPlaybackThread = new PlaybackThread(fromMs, toMs, loop, listener);

-        mPlaybackThread.start();

-    }

-

-    /**

-     * Stop the audio track playback. This method blocks until the ongoing

-     * playback is stopped.

-     *

-     * @return The accurate current time when stop is effective expressed in

-     *         milliseconds

-     */

-    public long stopPlayback() {

-        final long stopTimeMs;

-        if (mPlaybackThread != null) {

-            stopTimeMs = mPlaybackThread.stopPlayback();

-            mPlaybackThread = null;

-        } else {

-            stopTimeMs = 0;

-        }

-        return stopTimeMs;

-    }

-

-    /**

      * This API allows to generate a file containing the sample volume levels of

      * this audio track object. This function may take significant time and is

      * blocking. The filename can be retrieved using getAudioWaveformFilename().

diff --git a/media/java/android/media/videoeditor/MediaVideoItem.java b/media/java/android/media/videoeditor/MediaVideoItem.java
index dd12336..f71f4f4 100755
--- a/media/java/android/media/videoeditor/MediaVideoItem.java
+++ b/media/java/android/media/videoeditor/MediaVideoItem.java
@@ -19,7 +19,6 @@
 import java.io.IOException;

 

 import android.graphics.Bitmap;

-import android.util.Log;

 import android.view.SurfaceHolder;

 

 /**

@@ -27,9 +26,6 @@
  * {@hide}

  */

 public class MediaVideoItem extends MediaItem {

-    // Logging

-    private static final String TAG = "MediaVideoItem";

-

     // Instance variables

     private final int mWidth;

     private final int mHeight;

@@ -50,142 +46,6 @@
     private int mVolumePercentage;

     private boolean mMuted;

     private String mAudioWaveformFilename;

-    private PlaybackThread mPlaybackThread;

-

-    /**

-     * This listener interface is used by the MediaVideoItem to emit playback

-     * progress notifications. This callback should be invoked after the

-     * number of frames specified by

-     * {@link #startPlayback(SurfaceHolder surfaceHolder, long fromMs,

-     *           int callbackAfterFrameCount, PlaybackProgressListener listener)}

-     */

-    public interface PlaybackProgressListener {

-        /**

-         * This method notifies the listener of the current time position while

-         * playing a media item

-         *

-         * @param mediaItem The media item

-         * @param timeMs The current playback position (expressed in milliseconds

-         *            since the beginning of the media item).

-         * @param end true if the end of the media item was reached

-         */

-        public void onProgress(MediaVideoItem mediaItem, long timeMs, boolean end);

-    }

-

-    /**

-     * The playback thread

-     */

-    private class PlaybackThread extends Thread {

-        // Instance variables

-        private final static long FRAME_DURATION = 33;

-        private final PlaybackProgressListener mListener;

-        private final int mCallbackAfterFrameCount;

-        private final long mFromMs, mToMs;

-        private boolean mRun;

-        private final boolean mLoop;

-        private long mPositionMs;

-

-        /**

-         * Constructor

-         *

-         * @param fromMs The time (relative to the beginning of the media item)

-         *            at which the playback will start

-         * @param toMs The time (relative to the beginning of the media item) at

-         *            which the playback will stop. Use -1 to play to the end of

-         *            the media item

-         * @param loop true if the playback should be looped once it reaches the

-         *            end

-         * @param callbackAfterFrameCount The listener interface should be

-         *            invoked after the number of frames specified by this

-         *            parameter.

-         * @param listener The listener which will be notified of the playback

-         *            progress

-         */

-        public PlaybackThread(long fromMs, long toMs, boolean loop, int callbackAfterFrameCount,

-                PlaybackProgressListener listener) {

-            mPositionMs = mFromMs = fromMs;

-            if (toMs < 0) {

-                mToMs = mDurationMs;

-            } else {

-                mToMs = toMs;

-            }

-            mLoop = loop;

-            mCallbackAfterFrameCount = callbackAfterFrameCount;

-            mListener = listener;

-            mRun = true;

-        }

-

-        /*

-         * {@inheritDoc}

-         */

-        @Override

-        public void run() {

-            if (Log.isLoggable(TAG, Log.DEBUG)) {

-                Log.d(TAG, "===> PlaybackThread.run enter");

-            }

-            int frameCount = 0;

-            while (mRun) {

-                try {

-                    sleep(FRAME_DURATION);

-                } catch (InterruptedException ex) {

-                    break;

-                }

-                frameCount++;

-                mPositionMs += FRAME_DURATION;

-

-                if (mPositionMs >= mToMs) {

-                    if (!mLoop) {

-                        if (mListener != null) {

-                            mListener.onProgress(MediaVideoItem.this, mPositionMs, true);

-                        }

-                        if (Log.isLoggable(TAG, Log.DEBUG)) {

-                            Log.d(TAG, "PlaybackThread.run playback complete");

-                        }

-                        break;

-                    } else {

-                        // Fire a notification for the end of the clip

-                        if (mListener != null) {

-                            mListener.onProgress(MediaVideoItem.this, mToMs, false);

-                        }

-

-                        // Rewind

-                        mPositionMs = mFromMs;

-                        if (mListener != null) {

-                            mListener.onProgress(MediaVideoItem.this, mPositionMs, false);

-                        }

-                        if (Log.isLoggable(TAG, Log.DEBUG)) {

-                            Log.d(TAG, "PlaybackThread.run playback complete");

-                        }

-                        frameCount = 0;

-                    }

-                } else {

-                    if (frameCount == mCallbackAfterFrameCount) {

-                        if (mListener != null) {

-                            mListener.onProgress(MediaVideoItem.this, mPositionMs, false);

-                        }

-                        frameCount = 0;

-                    }

-                }

-            }

-            if (Log.isLoggable(TAG, Log.DEBUG)) {

-                Log.d(TAG, "===> PlaybackThread.run exit");

-            }

-        }

-

-        /**

-         * Stop the playback

-         *

-         * @return The stop position

-         */

-        public long stopPlayback() {

-            mRun = false;

-            try {

-                join();

-            } catch (InterruptedException ex) {

-            }

-            return mPositionMs;

-        }

-    };

 

     /**

      * An object of this type cannot be instantiated with a default constructor

@@ -408,57 +268,6 @@
     }

 

     /**

-     * Start the playback of this media item. This method does not block (does

-     * not wait for the playback to complete). The PlaybackProgressListener

-     * allows to track the progress at the time interval determined by the

-     * callbackAfterFrameCount parameter. The SurfaceHolder has to be created

-     * and ready for use before calling this method.

-     *

-     * @param surfaceHolder SurfaceHolder where the frames are rendered.

-     * @param fromMs The time (relative to the beginning of the media item) at

-     *            which the playback will start

-     * @param toMs The time (relative to the beginning of the media item) at

-     *            which the playback will stop. Use -1 to play to the end of the

-     *            media item

-     * @param loop true if the playback should be looped once it reaches the end

-     * @param callbackAfterFrameCount The listener interface should be invoked

-     *            after the number of frames specified by this parameter.

-     * @param listener The listener which will be notified of the playback

-     *            progress

-     * @throws IllegalArgumentException if fromMs or toMs is beyond the playback

-     *             duration

-     * @throws IllegalStateException if a playback, preview or an export is

-     *             already in progress

-     */

-    public void startPlayback(SurfaceHolder surfaceHolder, long fromMs, long toMs, boolean loop,

-            int callbackAfterFrameCount, PlaybackProgressListener listener) {

-        if (fromMs >= mDurationMs) {

-            return;

-        }

-        mPlaybackThread = new PlaybackThread(fromMs, toMs, loop, callbackAfterFrameCount,

-                listener);

-        mPlaybackThread.start();

-    }

-

-    /**

-     * Stop the media item playback. This method blocks until the ongoing

-     * playback is stopped.

-     *

-     * @return The accurate current time when stop is effective expressed in

-     *         milliseconds

-     */

-    public long stopPlayback() {

-        final long stopTimeMs;

-        if (mPlaybackThread != null) {

-            stopTimeMs = mPlaybackThread.stopPlayback();

-            mPlaybackThread = null;

-        } else {

-            stopTimeMs = 0;

-        }

-        return stopTimeMs;

-    }

-

-    /**

      * This API allows to generate a file containing the sample volume levels of

      * the Audio track of this media item. This function may take significant

      * time and is blocking. The file can be retrieved using