/samples/browseable/MediaRouter/src/com.example.android.mediarouter/player/PlaylistItem.java

https://gitlab.com/vicidroiddev/platform_development · Java · 130 lines · 90 code · 20 blank · 20 comment · 1 complexity · 500ba1444bbdd8c97f0813fe8cb26620 MD5 · raw file

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