public final class

MediaActionSoundCompat

extends java.lang.Object

 java.lang.Object

↳androidx.camera.core.internal.compat.MediaActionSoundCompat

Gradle dependencies

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

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

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

Overview

Helper for accessing features of in a backwards compatible fashion.

Summary

Methods
public static booleanmustPlayShutterSound()

Returns whether the shutter sound must be played in accordance to regional restrictions.

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

Methods

public static boolean mustPlayShutterSound()

Returns whether the shutter sound must be played in accordance to regional restrictions.

This method provides the general rule of playing shutter sounds. The exact requirements of playing shutter sounds may vary among regions.

For image capture, the shutter sound is recommended to be played when receiving or . For video capture, it's recommended to play the start recording sound when receiving VideoRecordEvent.Start and the stop recording sound when receiving VideoRecordEvent.Finalize.

To play the system default sounds, it's recommended to use . For image capture, play . For video capture, play and .

Returns:

true if shutter sound must be played, otherwise false.

Source

/*
 * Copyright 2023 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.core.internal.compat;

import android.media.MediaActionSound;
import android.os.Build;

import androidx.camera.core.ImageCapture;

/**
 * Helper for accessing features of {@link MediaActionSound} in a backwards compatible fashion.
 */
public final class MediaActionSoundCompat {

    /**
     * Returns whether the shutter sound must be played in accordance to regional restrictions.
     *
     * <p>This method provides the general rule of playing shutter sounds. The exact
     * requirements of playing shutter sounds may vary among regions.
     *
     * <p>For image capture, the shutter sound is recommended to be played when receiving
     * {@link ImageCapture.OnImageCapturedCallback#onCaptureStarted()} or
     * {@link ImageCapture.OnImageSavedCallback#onCaptureStarted()}. For video capture, it's
     * recommended to play the start recording sound when receiving
     * {@code VideoRecordEvent.Start} and the stop recording sound when receiving
     * {@code VideoRecordEvent.Finalize}.
     *
     * <p>To play the system default sounds, it's recommended to use
     * {@link MediaActionSound#play(int)}. For image capture, play
     * {@link MediaActionSound#SHUTTER_CLICK}. For video capture, play
     * {@link MediaActionSound#START_VIDEO_RECORDING} and
     * {@link MediaActionSound#STOP_VIDEO_RECORDING}.
     *
     * @return {@code true} if shutter sound must be played, otherwise {@code false}.
     */
    public static boolean mustPlayShutterSound() {
        if (Build.VERSION.SDK_INT >= 33) {
            return MediaActionSoundCompatApi33Impl.mustPlayShutterSound();
        } else {
            return MediaActionSoundCompatBaseImpl.mustPlayShutterSound();
        }
    }

    // Class should not be instantiated.
    private MediaActionSoundCompat() {
    }
}