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

Commit 3355bd2f authored by Simon Bowden's avatar Simon Bowden
Browse files

Support checking hasHapticChannels on a MediaPlayer.

Propagates the haptic channels key from the MediaFormat through to
avoid needing to re-open the file with a MediaExtractor.

Test: manual check with files that have haptic channels
Change-Id: I3c5cb10f513b03e569b2b49aa9a10db680bebfc0
Bug: 240621827
parent a18b921f
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -2496,11 +2496,21 @@ public class MediaPlayer extends PlayerBase
            return language == null ? "und" : language;
        }

        /**
         * Returns whether this track contains haptic channels in the audio track.
         * @hide
         */
        public boolean hasHapticChannels() {
            return mFormat != null && mFormat.containsKey(MediaFormat.KEY_HAPTIC_CHANNEL_COUNT)
                    && mFormat.getInteger(MediaFormat.KEY_HAPTIC_CHANNEL_COUNT) > 0;
        }

        /**
         * Gets the {@link MediaFormat} of the track.  If the format is
         * unknown or could not be determined, null is returned.
         */
        public MediaFormat getFormat() {
            // Note: The format isn't exposed for audio because it is incomplete.
            if (mTrackType == MEDIA_TRACK_TYPE_TIMEDTEXT
                    || mTrackType == MEDIA_TRACK_TYPE_SUBTITLE) {
                return mFormat;
@@ -2543,6 +2553,11 @@ public class MediaPlayer extends PlayerBase
                mFormat.setInteger(MediaFormat.KEY_IS_AUTOSELECT, in.readInt());
                mFormat.setInteger(MediaFormat.KEY_IS_DEFAULT, in.readInt());
                mFormat.setInteger(MediaFormat.KEY_IS_FORCED_SUBTITLE, in.readInt());
            } else if (mTrackType == MEDIA_TRACK_TYPE_AUDIO) {
                boolean hasHapticChannels = in.readBoolean();
                if (hasHapticChannels) {
                    mFormat.setInteger(MediaFormat.KEY_HAPTIC_CHANNEL_COUNT, in.readInt());
                }
            }
        }

@@ -2573,6 +2588,13 @@ public class MediaPlayer extends PlayerBase
                dest.writeInt(mFormat.getInteger(MediaFormat.KEY_IS_AUTOSELECT));
                dest.writeInt(mFormat.getInteger(MediaFormat.KEY_IS_DEFAULT));
                dest.writeInt(mFormat.getInteger(MediaFormat.KEY_IS_FORCED_SUBTITLE));
            } else if (mTrackType == MEDIA_TRACK_TYPE_AUDIO) {
                boolean hasHapticChannels =
                        mFormat.containsKey(MediaFormat.KEY_HAPTIC_CHANNEL_COUNT);
                dest.writeBoolean(hasHapticChannels);
                if (hasHapticChannels) {
                    dest.writeInt(mFormat.getInteger(MediaFormat.KEY_HAPTIC_CHANNEL_COUNT));
                }
            }
        }