public abstract class

OutputOptions

extends java.lang.Object

 java.lang.Object

↳androidx.camera.video.OutputOptions

Subclasses:

MediaStoreOutputOptions, FileOutputOptions, FileDescriptorOutputOptions

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-video', version: '1.5.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-video
  • version: 1.5.0-alpha01

Artifact androidx.camera:camera-video:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Options for configuring output destination for generating a recording.

A PendingRecording can be generated with Recorder.prepareRecording(Context, FileOutputOptions) for different types of output destination, such as FileOutputOptions, FileDescriptorOutputOptions and MediaStoreOutputOptions.

Summary

Fields
public static final intDURATION_UNLIMITED

Represents an unlimited duration.

public static final intFILE_SIZE_UNLIMITED

Represents an unbound file size.

Methods
public longgetDurationLimitMillis()

Gets the limit for the video duration in milliseconds.

public longgetFileSizeLimit()

Gets the limit for the file size in bytes.

public LocationgetLocation()

Returns a object representing the geographic location where the video was recorded.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final int FILE_SIZE_UNLIMITED

Represents an unbound file size.

public static final int DURATION_UNLIMITED

Represents an unlimited duration.

Methods

public long getFileSizeLimit()

Gets the limit for the file size in bytes.

Returns:

the file size limit in bytes or OutputOptions.FILE_SIZE_UNLIMITED if it's unlimited.

public Location getLocation()

Returns a object representing the geographic location where the video was recorded.

Returns:

the location object or null if no location was set.

public long getDurationLimitMillis()

Gets the limit for the video duration in milliseconds.

Returns:

the video duration limit in milliseconds or OutputOptions.DURATION_UNLIMITED if it's unlimited.

Source

/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.camera.video;

import android.location.Location;

import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Preconditions;

/**
 * Options for configuring output destination for generating a recording.
 *
 * <p>A {@link PendingRecording} can be generated with {@link Recorder#prepareRecording} for
 * different types of output destination, such as {@link FileOutputOptions},
 * {@link FileDescriptorOutputOptions} and {@link MediaStoreOutputOptions}.
 *
 * @see FileOutputOptions
 * @see FileDescriptorOutputOptions
 * @see MediaStoreOutputOptions
 */
public abstract class OutputOptions {

    /** Represents an unbound file size. */
    public static final int FILE_SIZE_UNLIMITED = 0;

    /** Represents an unlimited duration. */
    public static final int DURATION_UNLIMITED = 0;

    private final OutputOptionsInternal mOutputOptionsInternal;

    OutputOptions(@NonNull OutputOptionsInternal outputOptionsInternal) {
        mOutputOptionsInternal = outputOptionsInternal;
    }

    /**
     * Gets the limit for the file size in bytes.
     *
     * @return the file size limit in bytes or {@link #FILE_SIZE_UNLIMITED} if it's unlimited.
     */
    @IntRange(from = 0)
    public long getFileSizeLimit() {
        return mOutputOptionsInternal.getFileSizeLimit();
    }

    /**
     * Returns a {@link Location} object representing the geographic location where the video was
     * recorded.
     *
     * @return the location object or {@code null} if no location was set.
     */
    @Nullable
    public Location getLocation() {
        return mOutputOptionsInternal.getLocation();
    }

    /**
     * Gets the limit for the video duration in milliseconds.
     *
     * @return the video duration limit in milliseconds or {@link #DURATION_UNLIMITED} if it's
     * unlimited.
     */
    @IntRange(from = 0)
    public long getDurationLimitMillis() {
        return mOutputOptionsInternal.getDurationLimitMillis();
    }

    /**
     * The builder of the {@link OutputOptions}.
     */
    @SuppressWarnings("unchecked") // Cast to type B
    abstract static class Builder<T extends OutputOptions, B> {

        final OutputOptionsInternal.Builder<?> mRootInternalBuilder;

        Builder(@NonNull OutputOptionsInternal.Builder<?> builder) {
            mRootInternalBuilder = builder;
            // Apply default value
            mRootInternalBuilder.setFileSizeLimit(FILE_SIZE_UNLIMITED);
            mRootInternalBuilder.setDurationLimitMillis(DURATION_UNLIMITED);
        }

        /**
         * Sets the limit for the file length in bytes.
         *
         * <p>When used with {@link Recorder} to generate recording, if the specified file size
         * limit is reached while the recording is being recorded, the recording will be
         * finalized with {@link VideoRecordEvent.Finalize#ERROR_FILE_SIZE_LIMIT_REACHED}.
         *
         * <p>If not set or set with zero, the file size will be {@linkplain #FILE_SIZE_UNLIMITED
         * unlimited}. If set with a negative value, an {@link IllegalArgumentException} will be
         * thrown.
         *
         * @param fileSizeLimitBytes the file size limit in bytes.
         * @return this Builder.
         * @throws IllegalArgumentException if the specified file size limit is negative.
         */
        @NonNull
        public B setFileSizeLimit(@IntRange(from = 0) long fileSizeLimitBytes) {
            Preconditions.checkArgument(fileSizeLimitBytes >= 0, "The specified file size limit "
                    + "can't be negative.");
            mRootInternalBuilder.setFileSizeLimit(fileSizeLimitBytes);
            return (B) this;
        }

        /**
         * Sets the limit for the video duration in milliseconds.
         *
         * <p>When used to generate recording with {@link Recorder}, if the specified duration
         * limit is reached while the recording is being recorded, the recording will be
         * finalized with {@link VideoRecordEvent.Finalize#ERROR_DURATION_LIMIT_REACHED}.
         *
         * <p>If not set or set with zero, the duration will be {@linkplain #DURATION_UNLIMITED
         * unlimited}. If set with a negative value, an {@link IllegalArgumentException} will be
         * thrown.
         *
         * @param durationLimitMillis the video duration limit in milliseconds.
         * @return this Builder.
         * @throws IllegalArgumentException if the specified duration limit is negative.
         */
        @NonNull
        public B setDurationLimitMillis(@IntRange(from = 0) long durationLimitMillis) {
            Preconditions.checkArgument(durationLimitMillis >= 0, "The specified duration limit "
                    + "can't be negative.");
            mRootInternalBuilder.setDurationLimitMillis(durationLimitMillis);
            return (B) this;
        }

        /**
         * Sets a {@link Location} object representing a geographic location where the video was
         * recorded.
         *
         * <p>When use with {@link Recorder}, the geographic location is stored in udta box if the
         * output format is MP4, and is ignored for other formats. The geographic location is
         * stored according to ISO-6709 standard.
         *
         * <p>If {@code null}, no location information will be saved with the video. Default
         * value is {@code null}.
         *
         * @throws IllegalArgumentException if the latitude of the location is not in the range
         * {@code [-90, 90]} or the longitude of the location is not in the range {@code [-180,
         * 180]}.
         */
        @NonNull
        public B setLocation(@Nullable Location location) {
            if (location != null) {
                Preconditions.checkArgument(
                        location.getLatitude() >= -90 && location.getLatitude() <= 90,
                        "Latitude must be in the range [-90, 90]");
                Preconditions.checkArgument(
                        location.getLongitude() >= -180 && location.getLongitude() <= 180,
                        "Longitude must be in the range [-180, 180]");
            }
            mRootInternalBuilder.setLocation(location);
            return (B) this;
        }

        /**
         * Builds the {@link OutputOptions} instance.
         */
        @NonNull
        abstract T build();
    }

    // A base class of a @AutoValue class
    abstract static class OutputOptionsInternal {

        @IntRange(from = 0)
        abstract long getFileSizeLimit();

        @IntRange(from = 0)
        abstract long getDurationLimitMillis();

        @Nullable
        abstract Location getLocation();

        // A base class of a @AutoValue.Builder class
        @SuppressWarnings("NullableProblems") // Nullable problem in AutoValue generated class
        abstract static class Builder<B> {

            @NonNull
            abstract B setFileSizeLimit(@IntRange(from = 0) long fileSizeLimitBytes);

            @NonNull
            abstract B setDurationLimitMillis(@IntRange(from = 0) long durationLimitMillis);

            @NonNull
            abstract B setLocation(@Nullable Location location);

            @NonNull
            abstract OutputOptionsInternal build();
        }
    }
}