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

Commit 61f91845 authored by Gil Dobjanschi's avatar Gil Dobjanschi
Browse files

Added mute APIs for MediaVideoItem and AudioTrack

Change-Id: I2e4e8b213a5d19f895d9e3431b7d4f1acad70762
parent f124ce73
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -32,14 +32,15 @@ public class AudioTrack {
    // Instance variables
    private final String mUniqueId;
    private final String mFilename;
    private final long mDurationMs;
    private long mStartTimeMs;
    private long mTimelineDurationMs;
    private int mVolumePercent;
    private long mBeginBoundaryTimeMs;
    private long mEndBoundaryTimeMs;
    private boolean mLoop;
    private boolean mMuted;

    private final long mDurationMs;
    private final int mAudioChannels;
    private final int mAudioType;
    private final int mAudioBitrate;
@@ -217,6 +218,9 @@ public class AudioTrack {
        // By default loop is disabled
        mLoop = false;

        // By default the audio track is not muted
        mMuted = false;

        // Ducking is enabled by default
        mDuckingThreshold = 0;
        mDuckingLowVolume = 0;
@@ -239,12 +243,13 @@ public class AudioTrack {
     *            beginning of the audio track)
     * @param loop true to loop the audio track
     * @param volume The volume in percentage
     * @param muted true if the audio track is muted
     * @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 {
            boolean loop, int volume, boolean muted, String audioWaveformFilename) throws IOException {
        mUniqueId = audioTrackId;
        mFilename = filename;
        mStartTimeMs = startTimeMs;
@@ -266,6 +271,7 @@ public class AudioTrack {
        mEndBoundaryTimeMs = endMs;

        mLoop = loop;
        mMuted = muted;

        mAudioWaveformFilename = audioWaveformFilename;
    }
@@ -340,6 +346,20 @@ public class AudioTrack {
        return mVolumePercent;
    }

    /**
     * @param muted true to mute the audio track
     */
    public void setMute(boolean muted) {
        mMuted = muted;
    }

    /**
     * @return true if the audio track is muted
     */
    public boolean isMuted() {
        return mMuted;
    }

    /**
     * Set the start time of this audio track relative to the storyboard
     * timeline. Default value is 0.
+28 −4
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ public class MediaVideoItem extends MediaItem {
    private long mBeginBoundaryTimeMs;
    private long mEndBoundaryTimeMs;
    private int mVolumePercentage;
    private boolean mMuted;
    private String mAudioWaveformFilename;
    private PlaybackThread mPlaybackThread;

@@ -206,7 +207,7 @@ public class MediaVideoItem extends MediaItem {
     */
    public MediaVideoItem(String mediaItemId, String filename, int renderingMode)
        throws IOException {
        this(mediaItemId, filename, renderingMode, null);
        this(mediaItemId, filename, renderingMode, 0, END_OF_FILE, 100, false, null);
    }

    /**
@@ -215,11 +216,19 @@ public class MediaVideoItem extends MediaItem {
     * @param mediaItemId The MediaItem id
     * @param filename The image file name
     * @param renderingMode The rendering mode
     * @param beginMs Start time in milliseconds. Set to 0 to extract from the
     *           beginning
     * @param endMs End time in milliseconds. Set to {@link #END_OF_FILE} to
     *           extract until the end
     * @param volumePercent in %/. 100% means no change; 50% means half value, 200%
     *            means double, 0% means silent.
     * @param muted true if the audio is muted
     * @param audioWaveformFilename The name of the audio waveform file
     *
     * @throws IOException if the file cannot be opened for reading
     */
    MediaVideoItem(String mediaItemId, String filename, int renderingMode,
            long beginMs, long endMs, int volumePercent, boolean muted,
            String audioWaveformFilename)  throws IOException {
        super(mediaItemId, filename, renderingMode);
        // TODO: Set these variables correctly
@@ -239,9 +248,10 @@ public class MediaVideoItem extends MediaItem {
        mAudioChannels = 2;
        mAudioSamplingFrequency = 16000;

        mBeginBoundaryTimeMs = 0;
        mEndBoundaryTimeMs = mDurationMs;
        mVolumePercentage = 100;
        mBeginBoundaryTimeMs = beginMs;
        mEndBoundaryTimeMs = endMs == END_OF_FILE ? mDurationMs : endMs;
        mVolumePercentage = volumePercent;
        mMuted = muted;
        mAudioWaveformFilename = audioWaveformFilename;
    }

@@ -538,6 +548,20 @@ public class MediaVideoItem extends MediaItem {
        return mVolumePercentage;
    }

    /**
     * @param muted true to mute the media item
     */
    public void setMute(boolean muted) {
        mMuted = muted;
    }

    /**
     * @return true if the media item is muted
     */
    public boolean isMuted() {
        return mMuted;
    }

    /**
     * @return The video type
     */
+15 −2
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ public class VideoEditorTestImpl implements VideoEditor {
    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";
    private static final String ATTR_MUTED = "muted";

    // Instance variables
    private long mDurationMs;
@@ -582,6 +583,7 @@ public class VideoEditorTestImpl implements VideoEditor {
                        .attribute("", ATTR_BEGIN_TIME, Long.toString(mvi.getBoundaryBeginTime()));
                serializer.attribute("", ATTR_END_TIME, Long.toString(mvi.getBoundaryEndTime()));
                serializer.attribute("", ATTR_VOLUME, Integer.toString(mvi.getVolume()));
                serializer.attribute("", ATTR_MUTED, Boolean.toString(mvi.isMuted()));
                if (mvi.getAudioWaveformFilename() != null) {
                    serializer.attribute("", ATTR_AUDIO_WAVEFORM_FILENAME,
                            mvi.getAudioWaveformFilename());
@@ -713,6 +715,7 @@ public class VideoEditorTestImpl implements VideoEditor {
            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_MUTED, Boolean.toString(at.isMuted()));
            serializer.attribute("", ATTR_LOOP, Boolean.toString(at.isLooping()));
            if (at.getAudioWaveformFilename() != null) {
                serializer.attribute("", ATTR_AUDIO_WAVEFORM_FILENAME,
@@ -765,10 +768,19 @@ public class VideoEditorTestImpl implements VideoEditor {
                            currentMediaItem = new MediaImageItem(mediaItemId, filename,
                                    durationMs, renderingMode);
                        } else if (MediaVideoItem.class.getSimpleName().equals(type)) {
                            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 muted = Boolean.parseBoolean(parser.getAttributeValue("",
                                    ATTR_MUTED));
                            final String audioWaveformFilename = parser.getAttributeValue("",
                                    ATTR_AUDIO_WAVEFORM_FILENAME);
                            currentMediaItem = new MediaVideoItem(mediaItemId, filename,
                                    renderingMode, audioWaveformFilename);
                                    renderingMode, beginMs, endMs, volume, muted,
                                    audioWaveformFilename);

                            final long beginTimeMs = Long.parseLong(parser.getAttributeValue("",
                                    ATTR_BEGIN_TIME));
@@ -1001,11 +1013,12 @@ public class VideoEditorTestImpl implements VideoEditor {
        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 muted = Boolean.parseBoolean(parser.getAttributeValue("", ATTR_MUTED));
        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);
                    beginMs, endMs, loop, volume, muted, waveformFilename);

            return audioTrack;
        } catch (IOException ex) {