1 /* 2 * Copyright (C) 2016 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.bluetooth.avrcpcontroller; 18 19 import android.media.session.PlaybackState; 20 import android.util.Log; 21 22 /* 23 * Contains information about remote player 24 */ 25 class AvrcpPlayer { 26 private static final String TAG = "AvrcpPlayer"; 27 private static final boolean DBG = true; 28 29 public static final int INVALID_ID = -1; 30 31 private int mPlayStatus = PlaybackState.STATE_NONE; 32 private long mPlayTime = PlaybackState.PLAYBACK_POSITION_UNKNOWN; 33 private int mId; 34 private String mName = ""; 35 private int mPlayerType; 36 private TrackInfo mCurrentTrack = new TrackInfo(); 37 38 AvrcpPlayer() { 39 mId = INVALID_ID; 40 } 41 42 AvrcpPlayer(int id, String name, int transportFlags, int playStatus, int playerType) { 43 mId = id; 44 mName = name; 45 mPlayerType = playerType; 46 } 47 48 public int getId() { 49 return mId; 50 } 51 52 public String getName() { 53 return mName; 54 } 55 56 public void setPlayTime(int playTime) { 57 mPlayTime = playTime; 58 } 59 60 public long getPlayTime() { 61 return mPlayTime; 62 } 63 64 public void setPlayStatus(int playStatus) { 65 mPlayStatus = playStatus; 66 } 67 68 public PlaybackState getPlaybackState() { 69 if (DBG) { 70 Log.d(TAG, "getPlayBackState state " + mPlayStatus + " time " + mPlayTime); 71 } 72 73 long position = mPlayTime; 74 float speed = 1; 75 switch (mPlayStatus) { 76 case PlaybackState.STATE_STOPPED: 77 position = 0; 78 speed = 0; 79 break; 80 case PlaybackState.STATE_PAUSED: 81 speed = 0; 82 break; 83 case PlaybackState.STATE_FAST_FORWARDING: 84 speed = 3; 85 break; 86 case PlaybackState.STATE_REWINDING: 87 speed = -3; 88 break; 89 } 90 return new PlaybackState.Builder().setState(mPlayStatus, position, speed).build(); 91 } 92 93 public synchronized void updateCurrentTrack(TrackInfo update) { 94 mCurrentTrack = update; 95 } 96 97 public synchronized TrackInfo getCurrentTrack() { 98 return mCurrentTrack; 99 } 100 } 101