1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.photopicker.features.preview 18 19 import android.provider.CloudMediaProvider.CloudMediaSurfaceStateChangedCallback.PLAYBACK_STATE_BUFFERING 20 import android.provider.CloudMediaProvider.CloudMediaSurfaceStateChangedCallback.PLAYBACK_STATE_COMPLETED 21 import android.provider.CloudMediaProvider.CloudMediaSurfaceStateChangedCallback.PLAYBACK_STATE_ERROR_PERMANENT_FAILURE 22 import android.provider.CloudMediaProvider.CloudMediaSurfaceStateChangedCallback.PLAYBACK_STATE_ERROR_RETRIABLE_FAILURE 23 import android.provider.CloudMediaProvider.CloudMediaSurfaceStateChangedCallback.PLAYBACK_STATE_MEDIA_SIZE_CHANGED 24 import android.provider.CloudMediaProvider.CloudMediaSurfaceStateChangedCallback.PLAYBACK_STATE_PAUSED 25 import android.provider.CloudMediaProvider.CloudMediaSurfaceStateChangedCallback.PLAYBACK_STATE_READY 26 import android.provider.CloudMediaProvider.CloudMediaSurfaceStateChangedCallback.PLAYBACK_STATE_STARTED 27 28 /** 29 * Wrapper enum around the [CloudMediaProvider.CloudMediaSurfaceStateChangedCallback] state 30 * integers. 31 * 32 * @property state the underlying value as defined by the API. 33 */ 34 enum class PlaybackState(val state: Int) { 35 UNKNOWN(-1), 36 BUFFERING(PLAYBACK_STATE_BUFFERING), 37 READY(PLAYBACK_STATE_READY), 38 STARTED(PLAYBACK_STATE_STARTED), 39 PAUSED(PLAYBACK_STATE_PAUSED), 40 COMPLETED(PLAYBACK_STATE_COMPLETED), 41 MEDIA_SIZE_CHANGED(PLAYBACK_STATE_MEDIA_SIZE_CHANGED), 42 ERROR_RETRIABLE_FAILURE(PLAYBACK_STATE_ERROR_RETRIABLE_FAILURE), 43 ERROR_PERMANENT_FAILURE(PLAYBACK_STATE_ERROR_PERMANENT_FAILURE); 44 45 companion object { 46 /** 47 * @return Converts a [CloudMediaSurfaceStateChangedCallback] state int into the enum, or 48 * UNKNOWN if the value is not valid. 49 */ fromStateIntnull50 fun fromStateInt(value: Int): PlaybackState { 51 return PlaybackState.entries.find { it.state == value } ?: UNKNOWN 52 } 53 } 54 } 55