本文整理汇总了Java中android.media.browse.MediaBrowser.MediaItem方法的典型用法代码示例。如果您正苦于以下问题:Java MediaBrowser.MediaItem方法的具体用法?Java MediaBrowser.MediaItem怎么用?Java MediaBrowser.MediaItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.browse.MediaBrowser
的用法示例。
在下文中一共展示了MediaBrowser.MediaItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getView
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MediaBrowser.MediaItem item = getItem(position);
int itemState = MediaItemViewHolder.STATE_NONE;
if (item.isPlayable()) {
String itemMediaId = item.getDescription().getMediaId();
int playbackState = PlaybackState.STATE_NONE;
if (mCurrentState != null) {
playbackState = mCurrentState.getState();
}
if (mCurrentMetadata != null &&
itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) {
if (playbackState == PlaybackState.STATE_PLAYING ||
playbackState == PlaybackState.STATE_BUFFERING) {
itemState = MediaItemViewHolder.STATE_PLAYING;
} else if (playbackState != PlaybackState.STATE_ERROR) {
itemState = MediaItemViewHolder.STATE_PAUSED;
}
}
}
return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent,
item.getDescription(), itemState);
}
示例2: onChildrenLoaded
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
@Override
public void onChildrenLoaded(@NonNull String parentId,
@NonNull List<MediaBrowser.MediaItem> children) {
try {
LogHelper.d(TAG, "fragment onChildrenLoaded, parentId=" + parentId +
" count=" + children.size());
checkForUserVisibleErrors(children.isEmpty());
mBrowserAdapter.clear();
for (MediaBrowser.MediaItem item : children) {
mBrowserAdapter.add(item);
}
mBrowserAdapter.notifyDataSetChanged();
} catch (Throwable t) {
LogHelper.e(TAG, "Error on childrenloaded", t);
}
}
示例3: getView
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MediaBrowser.MediaItem item = getItem(position);
int itemState = MediaItemViewHolder.STATE_NONE;
if (item.isPlayable()) {
itemState = MediaItemViewHolder.STATE_PLAYABLE;
MediaController controller = ((Activity) getContext()).getMediaController();
if (controller != null && controller.getMetadata() != null) {
String currentPlaying = controller.getMetadata().getDescription().getMediaId();
String musicId = MediaIDHelper.extractMusicIDFromMediaID(
item.getDescription().getMediaId());
if (currentPlaying != null && currentPlaying.equals(musicId)) {
PlaybackState pbState = controller.getPlaybackState();
if (pbState == null || pbState.getState() == PlaybackState.STATE_ERROR) {
itemState = MediaItemViewHolder.STATE_NONE;
} else if (pbState.getState() == PlaybackState.STATE_PLAYING) {
itemState = MediaItemViewHolder.STATE_PLAYING;
} else {
itemState = MediaItemViewHolder.STATE_PAUSED;
}
}
}
}
return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent,
item.getDescription(), itemState);
}
示例4: getLibrary
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
private void getLibrary(final Result<List<MediaBrowser.MediaItem>> result) {
new SilentServiceTask<List<MusicFolder>>(downloadService) {
@Override
protected List<MusicFolder> doInBackground(MusicService musicService) throws Throwable {
return musicService.getMusicFolders(false, downloadService, null);
}
@Override
protected void done(List<MusicFolder> folders) {
List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
for(MusicFolder folder: folders) {
MediaDescription description = new MediaDescription.Builder()
.setTitle(folder.getName())
.setMediaId(MUSIC_FOLDER_PREFIX + folder.getId())
.build();
mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE));
}
result.sendResult(mediaItems);
}
}.execute();
result.detach();
}
示例5: getPodcasts
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
private void getPodcasts(final Result<List<MediaBrowser.MediaItem>> result) {
new SilentServiceTask<List<PodcastChannel>>(downloadService) {
@Override
protected List<PodcastChannel> doInBackground(MusicService musicService) throws Throwable {
return musicService.getPodcastChannels(false, downloadService, null);
}
@Override
protected void done(List<PodcastChannel> podcasts) {
List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
for(PodcastChannel podcast: podcasts) {
MediaDescription description = new MediaDescription.Builder()
.setTitle(podcast.getName())
.setMediaId(PODCAST_PREFIX + podcast.getId())
.build();
mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE));
}
result.sendResult(mediaItems);
}
}.execute();
result.detach();
}
示例6: fillMediaItems
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
private void fillMediaItems(List<MediaBrowser.MediaItem> mediaItems, String mediaId, String title, Uri icon, String subTitle, int playableOrBrowsable) {
mediaItems.add(new MediaBrowser.MediaItem(
new MediaDescription.Builder()
.setMediaId(mediaId)
.setTitle(title)
.setIconUri(icon)
.setSubtitle(subTitle)
.build(), playableOrBrowsable
));
}
示例7: getMediaItems
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
/**
*
* @return
*/
public static List<MediaBrowser.MediaItem> getMediaItems() {
List<MediaBrowser.MediaItem> retVal = new ArrayList<MediaBrowser.MediaItem>() ;
MediaBrowser.MediaItem newMediaItem = null ;
for (MediaMetadata aMetadata: musicCollectionMap.values()) {
newMediaItem = new MediaBrowser.MediaItem( aMetadata.getDescription(), MediaBrowser.MediaItem.FLAG_PLAYABLE) ;
retVal.add( newMediaItem) ;
}
return retVal ;
}
示例8: onChildrenLoaded
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
@Override
public void onChildrenLoaded(@NonNull String parentId,
@NonNull List<MediaBrowser.MediaItem> children) {
mListRowAdapter.clear();
for (MediaBrowser.MediaItem item : children) {
mListRowAdapter.add(item);
}
mListRowAdapter.notifyArrayItemRangeChanged(0, children.size());
}
示例9: getMediaItems
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
public static List<MediaBrowser.MediaItem> getMediaItems() {
List<MediaBrowser.MediaItem> result = new ArrayList<>();
for (MediaMetadata metadata: music.values()) {
result.add(new MediaBrowser.MediaItem(metadata.getDescription(),
MediaBrowser.MediaItem.FLAG_PLAYABLE));
}
return result;
}
示例10: onMediaItemSelected
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
private void onMediaItemSelected(MediaBrowser.MediaItem item) {
if (item.isPlayable()) {
// ------------ CHANGE 2 - REMOVE FOLLOWING LINES FOR PLAYBACK ON A SERVICE
MediaMetadata metadata = MusicLibrary.getMetadata(this, item.getMediaId());
mPlaybackManager.play(metadata);
updateMetadata(metadata);
/* ------------ CHANGE 2 - UNCOMMENT FOLLOWING LINES FOR PLAYBACK ON A SERVICE
getMediaController().getTransportControls().playFromMediaId(item.getMediaId(), null);
// ------------ CHANGE 2 - END OF PLAYBACK ON A SERVICE SNIPPET */
}
}
示例11: onMediaItemSelected
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
@Override
public void onMediaItemSelected(MediaBrowser.MediaItem item) {
LogHelper.d(TAG, "onMediaItemSelected, mediaId=" + item.getMediaId());
if (item.isPlayable()) {
getMediaController().getTransportControls().playFromMediaId(item.getMediaId(), null);
} else if (item.isBrowsable()) {
navigateToBrowser(item.getMediaId());
} else {
LogHelper.w(TAG, "Ignoring MediaItem that is neither browsable nor playable: ",
"mediaId=", item.getMediaId());
}
}
示例12: onChildrenLoaded
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
@Override
public void onChildrenLoaded(String parentId, List<MediaBrowser.MediaItem> children) {
try {
LogHelper.d(TAG, "fragment onChildrenLoaded, parentId=" + parentId +
" count=" + children.size());
checkForUserVisibleErrors(children.isEmpty());
mBrowserAdapter.clear();
for (MediaBrowser.MediaItem item : children) {
mBrowserAdapter.add(item);
}
mBrowserAdapter.notifyDataSetChanged();
} catch (Throwable t) {
LogHelper.e(TAG, "Error on childrenloaded", t);
}
}
示例13: getMusicDirectory
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
private void getMusicDirectory(final Result<List<MediaBrowser.MediaItem>> result, final String musicDirectoryId) {
new SilentServiceTask<MusicDirectory>(downloadService) {
@Override
protected MusicDirectory doInBackground(MusicService musicService) throws Throwable {
return musicService.getMusicDirectory(musicDirectoryId, "", false, downloadService, null);
}
@Override
protected void done(MusicDirectory directory) {
List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
addPlayOptions(mediaItems, musicDirectoryId, Constants.INTENT_EXTRA_NAME_ID);
for(Entry entry : directory.getChildren()) {
MediaDescription description;
if (entry.isDirectory()) {
// browse deeper
description = new MediaDescription.Builder()
.setTitle(entry.getTitle())
.setMediaId(MUSIC_DIRECTORY_CONTENTS_PREFIX + entry.getId())
.build();
} else {
// playback options for a single item
description = new MediaDescription.Builder()
.setTitle(entry.getTitle())
.setMediaId(MUSIC_DIRECTORY_PREFIX + entry.getId())
.build();
}
mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE));
}
result.sendResult(mediaItems);
}
}.execute();
result.detach();
}
示例14: getPodcastEpisodes
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
private void getPodcastEpisodes(final Result<List<MediaBrowser.MediaItem>> result, final String podcastId) {
new SilentServiceTask<MusicDirectory>(downloadService) {
@Override
protected MusicDirectory doInBackground(MusicService musicService) throws Throwable {
return musicService.getPodcastEpisodes(false, podcastId, downloadService, null);
}
@Override
protected void done(MusicDirectory podcasts) {
List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
for(Entry entry: podcasts.getChildren(false, true)) {
PodcastEpisode podcast = (PodcastEpisode) entry;
Bundle podcastExtras = new Bundle();
podcastExtras.putSerializable(Constants.INTENT_EXTRA_ENTRY, podcast);
podcastExtras.putString(Constants.INTENT_EXTRA_NAME_PODCAST_ID, podcast.getId());
MediaDescription description = new MediaDescription.Builder()
.setTitle(podcast.getTitle())
.setSubtitle(Util.formatDate(downloadService, podcast.getDate(), false))
.setMediaId(PODCAST_PREFIX + podcast.getId())
.setExtras(podcastExtras)
.build();
mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_PLAYABLE));
}
result.sendResult(mediaItems);
}
}.execute();
result.detach();
}
示例15: getPlayableMediaItemsByGenre
import android.media.browse.MediaBrowser; //导入方法依赖的package包/类
private List<MediaBrowser.MediaItem> getPlayableMediaItemsByGenre( String genre ) {
if( TextUtils.isEmpty( genre ) )
return null;
List<MediaBrowser.MediaItem> mediaItems = new ArrayList();
for( Song song : mSongs ) {
if( !TextUtils.isEmpty( song.getGenre() ) && genre.equalsIgnoreCase( song.getGenre() ) ) {
mediaItems.add( generatePlayableMediaItem( song ) );
}
}
return mediaItems;
}