blob: a5605384aca59e8b9e3a5f4476efdaf509edb8e1 [file] [log] [blame]
Alexander Lucas97842ff2014-03-07 14:56:55 -08001/*
2 * Copyright (C) 2013 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.example.android.mediarouter.player;
18
19import android.app.PendingIntent;
20import android.net.Uri;
21import android.os.SystemClock;
22import android.support.v7.media.MediaItemStatus;
23
24/**
25 * PlaylistItem helps keep track of the current status of an media item.
26 */
27public final class PlaylistItem {
28 // immutables
29 private final String mSessionId;
30 private final String mItemId;
31 private final Uri mUri;
32 private final String mMime;
33 private final PendingIntent mUpdateReceiver;
34 // changeable states
35 private int mPlaybackState = MediaItemStatus.PLAYBACK_STATE_PENDING;
36 private long mContentPosition;
37 private long mContentDuration;
38 private long mTimestamp;
39 private String mRemoteItemId;
40
41 public PlaylistItem(String qid, String iid, Uri uri, String mime, PendingIntent pi) {
42 mSessionId = qid;
43 mItemId = iid;
44 mUri = uri;
45 mMime = mime;
46 mUpdateReceiver = pi;
47 setTimestamp(SystemClock.elapsedRealtime());
48 }
49
50 public void setRemoteItemId(String riid) {
51 mRemoteItemId = riid;
52 }
53
54 public void setState(int state) {
55 mPlaybackState = state;
56 }
57
58 public void setPosition(long pos) {
59 mContentPosition = pos;
60 }
61
62 public void setTimestamp(long ts) {
63 mTimestamp = ts;
64 }
65
66 public void setDuration(long duration) {
67 mContentDuration = duration;
68 }
69
70 public String getSessionId() {
71 return mSessionId;
72 }
73
74 public String getItemId() {
75 return mItemId;
76 }
77
78 public String getRemoteItemId() {
79 return mRemoteItemId;
80 }
81
82 public Uri getUri() {
83 return mUri;
84 }
85
86 public PendingIntent getUpdateReceiver() {
87 return mUpdateReceiver;
88 }
89
90 public int getState() {
91 return mPlaybackState;
92 }
93
94 public long getPosition() {
95 return mContentPosition;
96 }
97
98 public long getDuration() {
99 return mContentDuration;
100 }
101
102 public long getTimestamp() {
103 return mTimestamp;
104 }
105
106 public MediaItemStatus getStatus() {
107 return new MediaItemStatus.Builder(mPlaybackState)
108 .setContentPosition(mContentPosition)
109 .setContentDuration(mContentDuration)
110 .setTimestamp(mTimestamp)
111 .build();
112 }
113
114 @Override
115 public String toString() {
116 String state[] = {
117 "PENDING",
118 "PLAYING",
119 "PAUSED",
120 "BUFFERING",
121 "FINISHED",
122 "CANCELED",
123 "INVALIDATED",
124 "ERROR"
125 };
126 return "[" + mSessionId + "|" + mItemId + "|"
127 + (mRemoteItemId != null ? mRemoteItemId : "-") + "|"
128 + state[mPlaybackState] + "] " + mUri.toString();
129 }
130}