Update browseable for MediaBrowserService sample.
Change-Id: I699899cc27b3f9b1f7003d050169e67b29c53eb7
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 4.7 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 3.2 KiB |
@@ -39,7 +39,6 @@ import android.os.PowerManager;
|
|||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.service.media.MediaBrowserService;
|
import android.service.media.MediaBrowserService;
|
||||||
|
|
||||||
import com.example.android.mediabrowserservice.PackageValidator;
|
|
||||||
import com.example.android.mediabrowserservice.model.MusicProvider;
|
import com.example.android.mediabrowserservice.model.MusicProvider;
|
||||||
import com.example.android.mediabrowserservice.utils.LogHelper;
|
import com.example.android.mediabrowserservice.utils.LogHelper;
|
||||||
import com.example.android.mediabrowserservice.utils.MediaIDHelper;
|
import com.example.android.mediabrowserservice.utils.MediaIDHelper;
|
||||||
@@ -379,6 +378,11 @@ public class MusicService extends MediaBrowserService implements OnPreparedListe
|
|||||||
@Override
|
@Override
|
||||||
public void onSkipToQueueItem(long queueId) {
|
public void onSkipToQueueItem(long queueId) {
|
||||||
LogHelper.d(TAG, "OnSkipToQueueItem:" + queueId);
|
LogHelper.d(TAG, "OnSkipToQueueItem:" + queueId);
|
||||||
|
|
||||||
|
if (mState == PlaybackState.STATE_PAUSED) {
|
||||||
|
mState = PlaybackState.STATE_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) {
|
if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) {
|
||||||
|
|
||||||
// set the current index on queue from the music Id:
|
// set the current index on queue from the music Id:
|
||||||
@@ -393,6 +397,10 @@ public class MusicService extends MediaBrowserService implements OnPreparedListe
|
|||||||
public void onPlayFromMediaId(String mediaId, Bundle extras) {
|
public void onPlayFromMediaId(String mediaId, Bundle extras) {
|
||||||
LogHelper.d(TAG, "playFromMediaId mediaId:", mediaId, " extras=", extras);
|
LogHelper.d(TAG, "playFromMediaId mediaId:", mediaId, " extras=", extras);
|
||||||
|
|
||||||
|
if (mState == PlaybackState.STATE_PAUSED) {
|
||||||
|
mState = PlaybackState.STATE_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
// The mediaId used here is not the unique musicId. This one comes from the
|
// The mediaId used here is not the unique musicId. This one comes from the
|
||||||
// MediaBrowser, and is actually a "hierarchy-aware mediaID": a concatenation of
|
// MediaBrowser, and is actually a "hierarchy-aware mediaID": a concatenation of
|
||||||
// the hierarchy in MediaBrowser and the actual unique musicID. This is necessary
|
// the hierarchy in MediaBrowser and the actual unique musicID. This is necessary
|
||||||
@@ -406,6 +414,7 @@ public class MusicService extends MediaBrowserService implements OnPreparedListe
|
|||||||
|
|
||||||
if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) {
|
if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) {
|
||||||
String uniqueMusicID = MediaIDHelper.extractMusicIDFromMediaID(mediaId);
|
String uniqueMusicID = MediaIDHelper.extractMusicIDFromMediaID(mediaId);
|
||||||
|
|
||||||
// set the current index on queue from the music Id:
|
// set the current index on queue from the music Id:
|
||||||
mCurrentIndexOnQueue = QueueHelper.getMusicIndexOnQueue(
|
mCurrentIndexOnQueue = QueueHelper.getMusicIndexOnQueue(
|
||||||
mPlayingQueue, uniqueMusicID);
|
mPlayingQueue, uniqueMusicID);
|
||||||
@@ -435,7 +444,7 @@ public class MusicService extends MediaBrowserService implements OnPreparedListe
|
|||||||
mCurrentIndexOnQueue = 0;
|
mCurrentIndexOnQueue = 0;
|
||||||
}
|
}
|
||||||
if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) {
|
if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) {
|
||||||
mState = PlaybackState.STATE_PLAYING;
|
mState = PlaybackState.STATE_STOPPED;
|
||||||
handlePlayRequest();
|
handlePlayRequest();
|
||||||
} else {
|
} else {
|
||||||
LogHelper.e(TAG, "skipToNext: cannot skip to next. next Index=" +
|
LogHelper.e(TAG, "skipToNext: cannot skip to next. next Index=" +
|
||||||
@@ -448,7 +457,6 @@ public class MusicService extends MediaBrowserService implements OnPreparedListe
|
|||||||
@Override
|
@Override
|
||||||
public void onSkipToPrevious() {
|
public void onSkipToPrevious() {
|
||||||
LogHelper.d(TAG, "skipToPrevious");
|
LogHelper.d(TAG, "skipToPrevious");
|
||||||
|
|
||||||
mCurrentIndexOnQueue--;
|
mCurrentIndexOnQueue--;
|
||||||
if (mPlayingQueue != null && mCurrentIndexOnQueue < 0) {
|
if (mPlayingQueue != null && mCurrentIndexOnQueue < 0) {
|
||||||
// This sample's behavior: skipping to previous when in first song restarts the
|
// This sample's behavior: skipping to previous when in first song restarts the
|
||||||
@@ -456,7 +464,7 @@ public class MusicService extends MediaBrowserService implements OnPreparedListe
|
|||||||
mCurrentIndexOnQueue = 0;
|
mCurrentIndexOnQueue = 0;
|
||||||
}
|
}
|
||||||
if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) {
|
if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) {
|
||||||
mState = PlaybackState.STATE_PLAYING;
|
mState = PlaybackState.STATE_STOPPED;
|
||||||
handlePlayRequest();
|
handlePlayRequest();
|
||||||
} else {
|
} else {
|
||||||
LogHelper.e(TAG, "skipToPrevious: cannot skip to previous. previous Index=" +
|
LogHelper.e(TAG, "skipToPrevious: cannot skip to previous. previous Index=" +
|
||||||
@@ -486,12 +494,15 @@ public class MusicService extends MediaBrowserService implements OnPreparedListe
|
|||||||
public void onPlayFromSearch(String query, Bundle extras) {
|
public void onPlayFromSearch(String query, Bundle extras) {
|
||||||
LogHelper.d(TAG, "playFromSearch query=", query);
|
LogHelper.d(TAG, "playFromSearch query=", query);
|
||||||
|
|
||||||
|
if (mState == PlaybackState.STATE_PAUSED) {
|
||||||
|
mState = PlaybackState.STATE_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
mPlayingQueue = QueueHelper.getPlayingQueueFromSearch(query, mMusicProvider);
|
mPlayingQueue = QueueHelper.getPlayingQueueFromSearch(query, mMusicProvider);
|
||||||
LogHelper.d(TAG, "playFromSearch playqueue.length=" + mPlayingQueue.size());
|
LogHelper.d(TAG, "playFromSearch playqueue.length=" + mPlayingQueue.size());
|
||||||
mSession.setQueue(mPlayingQueue);
|
mSession.setQueue(mPlayingQueue);
|
||||||
|
|
||||||
if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) {
|
if (mPlayingQueue != null && !mPlayingQueue.isEmpty()) {
|
||||||
|
|
||||||
// start playing from the beginning of the queue
|
// start playing from the beginning of the queue
|
||||||
mCurrentIndexOnQueue = 0;
|
mCurrentIndexOnQueue = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user