Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ba5e918 authored by Hangyu Kuang's avatar Hangyu Kuang
Browse files

media: Address API review comments

Change setNextOutputFile to accept File instead of String. Also add new version
of setOutputFile to accept File.

Bug: 36791064
Test: CTS test.
Change-Id: I1a3d574e7cf36acbf181407131bc9dbf114d30de
parent 57af565f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -22981,11 +22981,12 @@ package android.media {
    method public void setMaxDuration(int) throws java.lang.IllegalArgumentException;
    method public void setMaxFileSize(long) throws java.lang.IllegalArgumentException;
    method public void setNextOutputFile(java.io.FileDescriptor) throws java.io.IOException, java.lang.IllegalStateException;
    method public void setNextOutputFile(java.lang.String) throws java.io.IOException, java.lang.IllegalStateException;
    method public void setNextOutputFile(java.io.File) throws java.io.IOException, java.lang.IllegalStateException;
    method public void setOnErrorListener(android.media.MediaRecorder.OnErrorListener);
    method public void setOnInfoListener(android.media.MediaRecorder.OnInfoListener);
    method public void setOrientationHint(int);
    method public void setOutputFile(java.io.FileDescriptor) throws java.lang.IllegalStateException;
    method public void setOutputFile(java.io.File);
    method public void setOutputFile(java.lang.String) throws java.lang.IllegalStateException;
    method public void setOutputFormat(int) throws java.lang.IllegalStateException;
    method public void setPreviewDisplay(android.view.Surface);
+2 −1
Original line number Diff line number Diff line
@@ -24810,11 +24810,12 @@ package android.media {
    method public void setMaxDuration(int) throws java.lang.IllegalArgumentException;
    method public void setMaxFileSize(long) throws java.lang.IllegalArgumentException;
    method public void setNextOutputFile(java.io.FileDescriptor) throws java.io.IOException, java.lang.IllegalStateException;
    method public void setNextOutputFile(java.lang.String) throws java.io.IOException, java.lang.IllegalStateException;
    method public void setNextOutputFile(java.io.File) throws java.io.IOException, java.lang.IllegalStateException;
    method public void setOnErrorListener(android.media.MediaRecorder.OnErrorListener);
    method public void setOnInfoListener(android.media.MediaRecorder.OnInfoListener);
    method public void setOrientationHint(int);
    method public void setOutputFile(java.io.FileDescriptor) throws java.lang.IllegalStateException;
    method public void setOutputFile(java.io.File);
    method public void setOutputFile(java.lang.String) throws java.lang.IllegalStateException;
    method public void setOutputFormat(int) throws java.lang.IllegalStateException;
    method public void setPreviewDisplay(android.view.Surface);
+2 −1
Original line number Diff line number Diff line
@@ -23088,11 +23088,12 @@ package android.media {
    method public void setMaxDuration(int) throws java.lang.IllegalArgumentException;
    method public void setMaxFileSize(long) throws java.lang.IllegalArgumentException;
    method public void setNextOutputFile(java.io.FileDescriptor) throws java.io.IOException, java.lang.IllegalStateException;
    method public void setNextOutputFile(java.lang.String) throws java.io.IOException, java.lang.IllegalStateException;
    method public void setNextOutputFile(java.io.File) throws java.io.IOException, java.lang.IllegalStateException;
    method public void setOnErrorListener(android.media.MediaRecorder.OnErrorListener);
    method public void setOnInfoListener(android.media.MediaRecorder.OnInfoListener);
    method public void setOrientationHint(int);
    method public void setOutputFile(java.io.FileDescriptor) throws java.lang.IllegalStateException;
    method public void setOutputFile(java.io.File);
    method public void setOutputFile(java.lang.String) throws java.lang.IllegalStateException;
    method public void setOutputFormat(int) throws java.lang.IllegalStateException;
    method public void setPreviewDisplay(android.view.Surface);
+38 −14
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.Message;
import android.util.Log;
import android.view.Surface;

import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.RandomAccessFile;
@@ -92,6 +93,7 @@ public class MediaRecorder

    private String mPath;
    private FileDescriptor mFd;
    private File mFile;
    private EventHandler mEventHandler;
    private OnErrorListener mOnErrorListener;
    private OnInfoListener mOnInfoListener;
@@ -804,9 +806,25 @@ public class MediaRecorder
    public void setOutputFile(FileDescriptor fd) throws IllegalStateException
    {
        mPath = null;
        mFile = null;
        mFd = fd;
    }

    /**
     * Pass in the file object to be written. Call this after setOutputFormat() but before prepare().
     * File should be seekable. After setting the next output file, application should not use the
     * file until {@link #stop}. Application is responsible for cleaning up unused files after
     * {@link #stop} is called.
     *
     * @param file the file object to be written into.
     */
    public void setOutputFile(File file)
    {
        mPath = null;
        mFd = null;
        mFile = file;
    }

    /**
     * Sets the next output file descriptor to be used when the maximum filesize is reached
     * on the prior output {@link #setOutputFile} or {@link #setNextOutputFile}). File descriptor
@@ -842,15 +860,16 @@ public class MediaRecorder
    public void setOutputFile(String path) throws IllegalStateException
    {
        mFd = null;
        mFile = null;
        mPath = path;
    }

    /**
     * Sets the next output file path to be used when the maximum filesize is reached
     * on the prior output {@link #setOutputFile} or {@link #setNextOutputFile}). File should
     * be seekable. After setting the next output file, application should not use the file
     * referenced by this file descriptor until {@link #stop}. Application must call this
     * after receiving on the {@link android.media.MediaRecorder.OnInfoListener} a "what" code of
     * Sets the next output file to be used when the maximum filesize is reached on the prior
     * output {@link #setOutputFile} or {@link #setNextOutputFile}). File should be seekable.
     * After setting the next output file, application should not use the file until {@link #stop}.
     * Application must call this after receiving on the
     * {@link android.media.MediaRecorder.OnInfoListener} a "what" code of
     * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING} and before receiving a "what" code of
     * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED}. The file is not used until switching to
     * that output. Application will receive {@link #MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED}
@@ -858,19 +877,17 @@ public class MediaRecorder
     * the previous one has not been used. Application is responsible for cleaning up unused files
     * after {@link #stop} is called.
     *
     * @param  path The pathname to use.
     * @param  file The file to use.
     * @throws IllegalStateException if it is called before prepare().
     * @throws IOException if setNextOutputFile fails otherwise.
     */
    public void setNextOutputFile(String path) throws IllegalStateException, IOException
    public void setNextOutputFile(File file) throws IllegalStateException, IOException
    {
        if (path != null) {
            RandomAccessFile file = new RandomAccessFile(path, "rws");
        RandomAccessFile f = new RandomAccessFile(file, "rws");
        try {
                _setNextOutputFile(file.getFD());
            _setNextOutputFile(f.getFD());
        } finally {
                file.close();
            }
            f.close();
        }
    }

@@ -899,6 +916,13 @@ public class MediaRecorder
            }
        } else if (mFd != null) {
            _setOutputFile(mFd);
        } else if (mFile != null) {
            RandomAccessFile file = new RandomAccessFile(mFile, "rws");
            try {
                _setOutputFile(file.getFD());
            } finally {
                file.close();
            }
        } else {
            throw new IOException("No valid output file");
        }