Loading packages/MediaComponents/src/com/android/media/MediaController2Impl.java +3 −2 Original line number Diff line number Diff line Loading @@ -225,7 +225,7 @@ public class MediaController2Impl implements MediaController2Provider { @Override public void play_impl() { sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_START); sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_PLAY); } @Override Loading Loading @@ -568,7 +568,8 @@ public class MediaController2Impl implements MediaController2Provider { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } controller.pushPlaybackStateChanges(PlaybackState2.fromBundle(state)); controller.pushPlaybackStateChanges( PlaybackState2.fromBundle(controller.getContext(), state)); } @Override Loading packages/MediaComponents/src/com/android/media/MediaSession2Impl.java +4 −14 Original line number Diff line number Diff line Loading @@ -639,20 +639,10 @@ public class MediaSession2Impl implements MediaSession2Provider { @Override public void addAllPredefinedCommands_impl() { // TODO(jaewan): Is there any better way than this? mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_START)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_PAUSE)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_STOP)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_PREV_ITEM)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_PREPARE)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_FAST_FORWARD)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_REWIND)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_SEEK_TO)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_SET_CURRENT_PLAYLIST_ITEM)); final int COMMAND_CODE_MAX = 22; for (int i = 1; i <= COMMAND_CODE_MAX; i++) { mCommands.add(new Command(mContext, i)); } } @Override Loading packages/MediaComponents/src/com/android/media/MediaSession2Stub.java +1 −1 Original line number Diff line number Diff line Loading @@ -192,7 +192,7 @@ public class MediaSession2Stub extends IMediaSession2.Stub { } switch (commandCode) { case MediaSession2.COMMAND_CODE_PLAYBACK_START: case MediaSession2.COMMAND_CODE_PLAYBACK_PLAY: session.getInstance().play(); break; case MediaSession2.COMMAND_CODE_PLAYBACK_PAUSE: Loading packages/MediaComponents/src/com/android/media/PlaybackState2Impl.java 0 → 100644 +146 −0 Original line number Diff line number Diff line /* * Copyright 2018 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 com.android.media; import android.content.Context; import android.media.PlaybackState2; import android.media.update.PlaybackState2Provider; import android.os.Bundle; public final class PlaybackState2Impl implements PlaybackState2Provider { /** * Keys used for converting a PlaybackState2 to a bundle object and vice versa. */ private static final String KEY_STATE = "android.media.playbackstate2.state"; private static final String KEY_POSITION = "android.media.playbackstate2.position"; private static final String KEY_BUFFERED_POSITION = "android.media.playbackstate2.buffered_position"; private static final String KEY_SPEED = "android.media.playbackstate2.speed"; private static final String KEY_ERROR_MESSAGE = "android.media.playbackstate2.error_message"; private static final String KEY_UPDATE_TIME = "android.media.playbackstate2.update_time"; private static final String KEY_ACTIVE_ITEM_ID = "android.media.playbackstate2.active_item_id"; private final Context mContext; private final PlaybackState2 mInstance; private final int mState; private final long mPosition; private final long mUpdateTime; private final float mSpeed; private final long mBufferedPosition; private final long mActiveItemId; private final CharSequence mErrorMessage; public PlaybackState2Impl(Context context, PlaybackState2 instance, int state, long position, long updateTime, float speed, long bufferedPosition, long activeItemId, CharSequence error) { mContext = context; mInstance = instance; mState = state; mPosition = position; mSpeed = speed; mUpdateTime = updateTime; mBufferedPosition = bufferedPosition; mActiveItemId = activeItemId; mErrorMessage = error; } @Override public String toString_impl() { StringBuilder bob = new StringBuilder("PlaybackState {"); bob.append("state=").append(mState); bob.append(", position=").append(mPosition); bob.append(", buffered position=").append(mBufferedPosition); bob.append(", speed=").append(mSpeed); bob.append(", updated=").append(mUpdateTime); bob.append(", active item id=").append(mActiveItemId); bob.append(", error=").append(mErrorMessage); bob.append("}"); return bob.toString(); } @Override public int getState_impl() { return mState; } @Override public long getPosition_impl() { return mPosition; } @Override public long getBufferedPosition_impl() { return mBufferedPosition; } @Override public float getPlaybackSpeed_impl() { return mSpeed; } @Override public CharSequence getErrorMessage_impl() { return mErrorMessage; } @Override public long getLastPositionUpdateTime_impl() { return mUpdateTime; } @Override public long getCurrentPlaylistItemIndex_impl() { return mActiveItemId; } @Override public Bundle toBundle_impl() { Bundle bundle = new Bundle(); bundle.putInt(KEY_STATE, mState); bundle.putLong(KEY_POSITION, mPosition); bundle.putLong(KEY_UPDATE_TIME, mUpdateTime); bundle.putFloat(KEY_SPEED, mSpeed); bundle.putLong(KEY_BUFFERED_POSITION, mBufferedPosition); bundle.putLong(KEY_ACTIVE_ITEM_ID, mActiveItemId); bundle.putCharSequence(KEY_ERROR_MESSAGE, mErrorMessage); return bundle; } public static PlaybackState2 fromBundle(Context context, Bundle bundle) { if (bundle == null) { return null; } if (!bundle.containsKey(KEY_STATE) || !bundle.containsKey(KEY_POSITION) || !bundle.containsKey(KEY_UPDATE_TIME) || !bundle.containsKey(KEY_SPEED) || !bundle.containsKey(KEY_BUFFERED_POSITION) || !bundle.containsKey(KEY_ACTIVE_ITEM_ID) || !bundle.containsKey(KEY_ERROR_MESSAGE)) { return null; } return new PlaybackState2(context, bundle.getInt(KEY_STATE), bundle.getLong(KEY_POSITION), bundle.getLong(KEY_UPDATE_TIME), bundle.getFloat(KEY_SPEED), bundle.getLong(KEY_BUFFERED_POSITION), bundle.getLong(KEY_ACTIVE_ITEM_ID), bundle.getCharSequence(KEY_ERROR_MESSAGE)); } } No newline at end of file packages/MediaComponents/src/com/android/media/update/ApiFactory.java +16 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import android.media.MediaSession2.ControllerInfo; import android.media.MediaSession2.PlaylistParams; import android.media.MediaSession2.SessionCallback; import android.media.MediaSessionService2; import android.media.PlaybackState2; import android.media.Rating2; import android.media.SessionPlayer2; import android.media.SessionToken2; Loading @@ -51,6 +52,7 @@ import android.media.update.MediaSession2Provider; import android.media.update.MediaSession2Provider.BuilderBaseProvider; import android.media.update.MediaSession2Provider.PlaylistParamsProvider; import android.media.update.MediaSessionService2Provider; import android.media.update.PlaybackState2Provider; import android.media.update.SessionPlayer2Provider; import android.media.update.SessionToken2Provider; import android.media.update.StaticProvider; Loading @@ -73,6 +75,7 @@ import com.android.media.MediaMetadata2Impl; import com.android.media.MediaSession2Impl; import com.android.media.MediaSession2Impl.PlaylistParamsImpl; import com.android.media.MediaSessionService2Impl; import com.android.media.PlaybackState2Impl; import com.android.media.Rating2Impl; import com.android.media.SessionToken2Impl; import com.android.media.VolumeProvider2Impl; Loading Loading @@ -267,4 +270,17 @@ public class ApiFactory implements StaticProvider { public Rating2 newPercentageRating_Rating2(Context context, float percent) { return Rating2Impl.newPercentageRating(context, percent); } @Override public PlaybackState2Provider createPlaybackState2(Context context, PlaybackState2 instance, int state, long position, long updateTime, float speed, long bufferedPosition, long activeItemId, CharSequence error) { return new PlaybackState2Impl(context, instance, state, position, updateTime, speed, bufferedPosition, activeItemId, error); } @Override public PlaybackState2 fromBundle_PlaybackState2(Context context, Bundle bundle) { return PlaybackState2Impl.fromBundle(context, bundle); } } Loading
packages/MediaComponents/src/com/android/media/MediaController2Impl.java +3 −2 Original line number Diff line number Diff line Loading @@ -225,7 +225,7 @@ public class MediaController2Impl implements MediaController2Provider { @Override public void play_impl() { sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_START); sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_PLAY); } @Override Loading Loading @@ -568,7 +568,8 @@ public class MediaController2Impl implements MediaController2Provider { Log.w(TAG, "Don't fail silently here. Highly likely a bug"); return; } controller.pushPlaybackStateChanges(PlaybackState2.fromBundle(state)); controller.pushPlaybackStateChanges( PlaybackState2.fromBundle(controller.getContext(), state)); } @Override Loading
packages/MediaComponents/src/com/android/media/MediaSession2Impl.java +4 −14 Original line number Diff line number Diff line Loading @@ -639,20 +639,10 @@ public class MediaSession2Impl implements MediaSession2Provider { @Override public void addAllPredefinedCommands_impl() { // TODO(jaewan): Is there any better way than this? mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_START)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_PAUSE)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_STOP)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_PREV_ITEM)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_PREPARE)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_FAST_FORWARD)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_REWIND)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_SEEK_TO)); mCommands.add(new Command(mContext, MediaSession2.COMMAND_CODE_PLAYBACK_SET_CURRENT_PLAYLIST_ITEM)); final int COMMAND_CODE_MAX = 22; for (int i = 1; i <= COMMAND_CODE_MAX; i++) { mCommands.add(new Command(mContext, i)); } } @Override Loading
packages/MediaComponents/src/com/android/media/MediaSession2Stub.java +1 −1 Original line number Diff line number Diff line Loading @@ -192,7 +192,7 @@ public class MediaSession2Stub extends IMediaSession2.Stub { } switch (commandCode) { case MediaSession2.COMMAND_CODE_PLAYBACK_START: case MediaSession2.COMMAND_CODE_PLAYBACK_PLAY: session.getInstance().play(); break; case MediaSession2.COMMAND_CODE_PLAYBACK_PAUSE: Loading
packages/MediaComponents/src/com/android/media/PlaybackState2Impl.java 0 → 100644 +146 −0 Original line number Diff line number Diff line /* * Copyright 2018 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 com.android.media; import android.content.Context; import android.media.PlaybackState2; import android.media.update.PlaybackState2Provider; import android.os.Bundle; public final class PlaybackState2Impl implements PlaybackState2Provider { /** * Keys used for converting a PlaybackState2 to a bundle object and vice versa. */ private static final String KEY_STATE = "android.media.playbackstate2.state"; private static final String KEY_POSITION = "android.media.playbackstate2.position"; private static final String KEY_BUFFERED_POSITION = "android.media.playbackstate2.buffered_position"; private static final String KEY_SPEED = "android.media.playbackstate2.speed"; private static final String KEY_ERROR_MESSAGE = "android.media.playbackstate2.error_message"; private static final String KEY_UPDATE_TIME = "android.media.playbackstate2.update_time"; private static final String KEY_ACTIVE_ITEM_ID = "android.media.playbackstate2.active_item_id"; private final Context mContext; private final PlaybackState2 mInstance; private final int mState; private final long mPosition; private final long mUpdateTime; private final float mSpeed; private final long mBufferedPosition; private final long mActiveItemId; private final CharSequence mErrorMessage; public PlaybackState2Impl(Context context, PlaybackState2 instance, int state, long position, long updateTime, float speed, long bufferedPosition, long activeItemId, CharSequence error) { mContext = context; mInstance = instance; mState = state; mPosition = position; mSpeed = speed; mUpdateTime = updateTime; mBufferedPosition = bufferedPosition; mActiveItemId = activeItemId; mErrorMessage = error; } @Override public String toString_impl() { StringBuilder bob = new StringBuilder("PlaybackState {"); bob.append("state=").append(mState); bob.append(", position=").append(mPosition); bob.append(", buffered position=").append(mBufferedPosition); bob.append(", speed=").append(mSpeed); bob.append(", updated=").append(mUpdateTime); bob.append(", active item id=").append(mActiveItemId); bob.append(", error=").append(mErrorMessage); bob.append("}"); return bob.toString(); } @Override public int getState_impl() { return mState; } @Override public long getPosition_impl() { return mPosition; } @Override public long getBufferedPosition_impl() { return mBufferedPosition; } @Override public float getPlaybackSpeed_impl() { return mSpeed; } @Override public CharSequence getErrorMessage_impl() { return mErrorMessage; } @Override public long getLastPositionUpdateTime_impl() { return mUpdateTime; } @Override public long getCurrentPlaylistItemIndex_impl() { return mActiveItemId; } @Override public Bundle toBundle_impl() { Bundle bundle = new Bundle(); bundle.putInt(KEY_STATE, mState); bundle.putLong(KEY_POSITION, mPosition); bundle.putLong(KEY_UPDATE_TIME, mUpdateTime); bundle.putFloat(KEY_SPEED, mSpeed); bundle.putLong(KEY_BUFFERED_POSITION, mBufferedPosition); bundle.putLong(KEY_ACTIVE_ITEM_ID, mActiveItemId); bundle.putCharSequence(KEY_ERROR_MESSAGE, mErrorMessage); return bundle; } public static PlaybackState2 fromBundle(Context context, Bundle bundle) { if (bundle == null) { return null; } if (!bundle.containsKey(KEY_STATE) || !bundle.containsKey(KEY_POSITION) || !bundle.containsKey(KEY_UPDATE_TIME) || !bundle.containsKey(KEY_SPEED) || !bundle.containsKey(KEY_BUFFERED_POSITION) || !bundle.containsKey(KEY_ACTIVE_ITEM_ID) || !bundle.containsKey(KEY_ERROR_MESSAGE)) { return null; } return new PlaybackState2(context, bundle.getInt(KEY_STATE), bundle.getLong(KEY_POSITION), bundle.getLong(KEY_UPDATE_TIME), bundle.getFloat(KEY_SPEED), bundle.getLong(KEY_BUFFERED_POSITION), bundle.getLong(KEY_ACTIVE_ITEM_ID), bundle.getCharSequence(KEY_ERROR_MESSAGE)); } } No newline at end of file
packages/MediaComponents/src/com/android/media/update/ApiFactory.java +16 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import android.media.MediaSession2.ControllerInfo; import android.media.MediaSession2.PlaylistParams; import android.media.MediaSession2.SessionCallback; import android.media.MediaSessionService2; import android.media.PlaybackState2; import android.media.Rating2; import android.media.SessionPlayer2; import android.media.SessionToken2; Loading @@ -51,6 +52,7 @@ import android.media.update.MediaSession2Provider; import android.media.update.MediaSession2Provider.BuilderBaseProvider; import android.media.update.MediaSession2Provider.PlaylistParamsProvider; import android.media.update.MediaSessionService2Provider; import android.media.update.PlaybackState2Provider; import android.media.update.SessionPlayer2Provider; import android.media.update.SessionToken2Provider; import android.media.update.StaticProvider; Loading @@ -73,6 +75,7 @@ import com.android.media.MediaMetadata2Impl; import com.android.media.MediaSession2Impl; import com.android.media.MediaSession2Impl.PlaylistParamsImpl; import com.android.media.MediaSessionService2Impl; import com.android.media.PlaybackState2Impl; import com.android.media.Rating2Impl; import com.android.media.SessionToken2Impl; import com.android.media.VolumeProvider2Impl; Loading Loading @@ -267,4 +270,17 @@ public class ApiFactory implements StaticProvider { public Rating2 newPercentageRating_Rating2(Context context, float percent) { return Rating2Impl.newPercentageRating(context, percent); } @Override public PlaybackState2Provider createPlaybackState2(Context context, PlaybackState2 instance, int state, long position, long updateTime, float speed, long bufferedPosition, long activeItemId, CharSequence error) { return new PlaybackState2Impl(context, instance, state, position, updateTime, speed, bufferedPosition, activeItemId, error); } @Override public PlaybackState2 fromBundle_PlaybackState2(Context context, Bundle bundle) { return PlaybackState2Impl.fromBundle(context, bundle); } }