本文整理汇总了Java中android.media.browse.MediaBrowser类的典型用法代码示例。如果您正苦于以下问题:Java MediaBrowser类的具体用法?Java MediaBrowser怎么用?Java MediaBrowser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaBrowser类属于android.media.browse包,在下文中一共展示了MediaBrowser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setMediaId
import android.media.browse.MediaBrowser; //导入依赖的package包/类
protected void setMediaId(String mediaId) {
LogHelper.d(TAG, "setMediaId: ", mediaId);
if (TextUtils.equals(mMediaId, mediaId)) {
return;
}
MediaBrowser mediaBrowser = mMediaFragmentListener.getMediaBrowser();
// First, unsubscribe from old mediaId:
if (mMediaId != null) {
mediaBrowser.unsubscribe(mMediaId);
}
if (mediaId == null) {
mediaId = mediaBrowser.getRoot();
}
mMediaId = mediaId;
mediaBrowser.subscribe(mMediaId, mSubscriptionCallback);
}
示例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: onStart
import android.media.browse.MediaBrowser; //导入依赖的package包/类
@Override
public void onStart() {
super.onStart();
// fetch browsing information to fill the listview:
MediaBrowser mediaBrowser = mMediaFragmentListener.getMediaBrowser();
LogHelper.d(TAG, "fragment.onStart, mediaId=", mMediaId,
" onConnected=" + mediaBrowser.isConnected());
if (mediaBrowser.isConnected()) {
onConnected();
}
// Registers BroadcastReceiver to track network connection changes.
this.getActivity().registerReceiver(mConnectivityChangeReceiver,
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
示例4: 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);
}
示例5: onCreate
import android.media.browse.MediaBrowser; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogHelper.d(TAG, "Activity onCreate");
// Since our app icon has the same color as colorPrimary, our entry in the Recent Apps
// list gets weird. We need to change either the icon or the color of the TaskDescription.
ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(
getTitle().toString(),
BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_white),
ResourceHelper.getThemeColor(this, R.attr.colorPrimary, android.R.color.darker_gray));
setTaskDescription(taskDesc);
// Connect a media browser just to get the media session token. There are other ways
// this can be done, for example by sharing the session token directly.
mMediaBrowser = new MediaBrowser(this,
new ComponentName(this, MusicService.class), mConnectionCallback, null);
}
示例6: 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);
}
示例7: getView
import android.media.browse.MediaBrowser; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MediaBrowser.MediaItem item = getItem(position);
int state = MediaItemViewHolder.STATE_NONE;
if (item.isPlayable()) {
state = 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)) {
if (controller.getPlaybackState().getState() ==
PlaybackState.STATE_PLAYING) {
state = MediaItemViewHolder.STATE_PLAYING;
} else if (controller.getPlaybackState().getState() !=
PlaybackState.STATE_ERROR) {
state = MediaItemViewHolder.STATE_PAUSED;
}
}
}
}
return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent,
item.getDescription(), state);
}
示例8: getAlbumLists
import android.media.browse.MediaBrowser; //导入依赖的package包/类
private void getAlbumLists(Result<List<MediaBrowser.MediaItem>> result) {
List<Integer> albums = new ArrayList<>();
albums.add(R.string.main_albums_newest);
albums.add(R.string.main_albums_random);
if(!Util.isTagBrowsing(downloadService)) {
albums.add(R.string.main_albums_highest);
}
albums.add(R.string.main_albums_starred);
albums.add(R.string.main_albums_recent);
albums.add(R.string.main_albums_frequent);
List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
for(Integer id: albums) {
MediaDescription description = new MediaDescription.Builder()
.setTitle(downloadService.getResources().getString(id))
.setMediaId(ALBUM_TYPE_PREFIX + id)
.build();
mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE));
}
result.sendResult(mediaItems);
}
示例9: 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();
}
示例10: getPlaylists
import android.media.browse.MediaBrowser; //导入依赖的package包/类
private void getPlaylists(final Result<List<MediaBrowser.MediaItem>> result) {
new SilentServiceTask<List<Playlist>>(downloadService) {
@Override
protected List<Playlist> doInBackground(MusicService musicService) throws Throwable {
return musicService.getPlaylists(false, downloadService, null);
}
@Override
protected void done(List<Playlist> playlists) {
List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
for(Playlist playlist: playlists) {
MediaDescription description = new MediaDescription.Builder()
.setTitle(playlist.getName())
.setMediaId(PLAYLIST_PREFIX + playlist.getId())
.build();
mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE));
}
result.sendResult(mediaItems);
}
}.execute();
result.detach();
}
示例11: 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();
}
示例12: generatePlayableMediaItem
import android.media.browse.MediaBrowser; //导入依赖的package包/类
private MediaBrowser.MediaItem generatePlayableMediaItem( Song song ) {
if( song == null )
return null;
MediaDescription.Builder mediaDescriptionBuilder = new MediaDescription.Builder();
mediaDescriptionBuilder.setMediaId( song.getuId() );
if( !TextUtils.isEmpty( song.getTitle() ) )
mediaDescriptionBuilder.setTitle( song.getTitle() );
if( !TextUtils.isEmpty( song.getArtist() ) )
mediaDescriptionBuilder.setSubtitle( song.getArtist() );
if( !TextUtils.isEmpty( song.getThumbnailUrl() ) )
mediaDescriptionBuilder.setIconUri( Uri.parse( song.getThumbnailUrl() ) );
return new MediaBrowser.MediaItem( mediaDescriptionBuilder.build(), MediaBrowser.MediaItem.FLAG_PLAYABLE );
}
示例13: 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
));
}
示例14: 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 ;
}
示例15: onCreate
import android.media.browse.MediaBrowser; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tv_vertical_grid);
mMediaId = getIntent().getStringExtra(TvBrowseActivity.SAVED_MEDIA_ID);
mTitle = getIntent().getStringExtra(TvBrowseActivity.BROWSE_TITLE);
getWindow().setBackgroundDrawableResource(R.drawable.bg);
mMediaBrowser = new MediaBrowser(this,
new ComponentName(this, MusicService.class),
mConnectionCallback, null);
}