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