android.media.browse.MediaBrowser Java Examples

The following examples show how to use android.media.browse.MediaBrowser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MusicPlayerActivity.java    From android-music-player with Apache License 2.0 7 votes vote down vote up
@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);
}
 
Example #2
Source File: AutoMediaBrowserService.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
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 );
}
 
Example #3
Source File: MusicPlayerActivity.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: MusicPlayerActivity.java    From android-music-player with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: MusicPlayerActivity.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #6
Source File: AutoMediaBrowserService.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: AutoMediaBrowserService.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private MediaBrowser.MediaItem generateBrowseableMediaItemByGenre( String genre ) {
    MediaDescription.Builder mediaDescriptionBuilder = new MediaDescription.Builder();
    mediaDescriptionBuilder.setMediaId( genre );
    mediaDescriptionBuilder.setTitle( genre );
    mediaDescriptionBuilder.setIconBitmap( BitmapFactory.decodeResource( getResources(), R.drawable.folder ) );

    return new MediaBrowser.MediaItem( mediaDescriptionBuilder.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE );
}
 
Example #8
Source File: MusicLibrary.java    From android-music-player with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #9
Source File: AutoMediaBrowserService.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private List<MediaBrowser.MediaItem> getMediaItemsById( String id ) {
    List<MediaBrowser.MediaItem> mediaItems = new ArrayList<MediaBrowser.MediaItem>();
    if( BROWSEABLE_ROOT.equalsIgnoreCase( id ) ) {
        mediaItems.add( generateBrowseableMediaItemByGenre(BROWSEABLE_CAJUN) );
        mediaItems.add( generateBrowseableMediaItemByGenre(BROWSEABLE_JAZZ) );
        mediaItems.add( generateBrowseableMediaItemByGenre(BROWSEABLE_ROCK) );
    } else if( !TextUtils.isEmpty( id ) ) {
        return getPlayableMediaItemsByGenre( id );
    }

    return mediaItems;
}
 
Example #10
Source File: AutoMediaBrowserService.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadChildren(String parentId, Result<List<MediaBrowser.MediaItem>> result) {

    List<MediaBrowser.MediaItem> items = getMediaItemsById( parentId );
    if( items != null ) {
        result.sendResult( items );
    }

}
 
Example #11
Source File: MusicLibrary.java    From android-music-player with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: MusicPlayerActivity.java    From android-music-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    mMediaBrowser = new MediaBrowser(this,
           new ComponentName(this, MusicService.class), mConnectionCallback, null);
    mMediaBrowser.connect();
}
 
Example #13
Source File: MusicPlayerActivity.java    From android-music-player with Apache License 2.0 5 votes vote down vote up
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 */
    }
}
 
Example #14
Source File: WearBrowserService.java    From Muzesto with GNU General Public License v3.0 5 votes vote down vote up
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
    ));
}
 
Example #15
Source File: MusicLibrary.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #16
Source File: MusicPlayerActivity.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    mMediaBrowser = new MediaBrowser(this,
           new ComponentName(this, MusicService.class), mConnectionCallback, null);
    mMediaBrowser.connect();
}
 
Example #17
Source File: MusicPlayerActivity.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
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 */
    }
}
 
Example #18
Source File: MusicLibrary.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #19
Source File: MusicPlayerActivity.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
private void onMediaLoaded(List<MediaBrowser.MediaItem> media) {
    mBrowserAdapter.clear();
    mBrowserAdapter.addAll(media);
    mBrowserAdapter.notifyDataSetChanged();
}
 
Example #20
Source File: MusicPlayerActivity.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
private void onMediaLoaded(List<MediaBrowser.MediaItem> media) {
    mBrowserAdapter.clear();
    mBrowserAdapter.addAll(media);
    mBrowserAdapter.notifyDataSetChanged();
}
 
Example #21
Source File: MusicPlayerActivity.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
private void onMediaItemSelected(MediaBrowser.MediaItem item) {
    if (item.isPlayable()) {
        getMediaController().getTransportControls().playFromMediaId(item.getMediaId(), null);
    }
}
 
Example #22
Source File: MusicPlayerActivity.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
public BrowseAdapter(Activity context) {
    super(context, R.layout.media_list_item, new ArrayList<MediaBrowser.MediaItem>());
}
 
Example #23
Source File: MusicPlayerActivity.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
@Override
public void onChildrenLoaded(String parentId, List<MediaBrowser.MediaItem> children) {
    onMediaLoaded(children);
}
 
Example #24
Source File: MusicPlayerActivity.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
public BrowseAdapter(Activity context) {
    super(context, R.layout.media_list_item, new ArrayList<MediaBrowser.MediaItem>());
}
 
Example #25
Source File: MusicPlayerActivity.java    From android-music-player with Apache License 2.0 4 votes vote down vote up
public BrowseAdapter(Activity context) {
    super(context, R.layout.media_list_item, new ArrayList<MediaBrowser.MediaItem>());
}
 
Example #26
Source File: MusicPlayerActivity.java    From android-music-player with Apache License 2.0 4 votes vote down vote up
private void onMediaItemSelected(MediaBrowser.MediaItem item) {
    if (item.isPlayable()) {
        getMediaController().getTransportControls().playFromMediaId(item.getMediaId(), null);
    }
}
 
Example #27
Source File: MusicPlayerActivity.java    From android-music-player with Apache License 2.0 4 votes vote down vote up
private void onMediaLoaded(List<MediaBrowser.MediaItem> media) {
    mBrowserAdapter.clear();
    mBrowserAdapter.addAll(media);
    mBrowserAdapter.notifyDataSetChanged();
}
 
Example #28
Source File: MusicPlayerActivity.java    From android-music-player with Apache License 2.0 4 votes vote down vote up
@Override
public void onChildrenLoaded(String parentId, List<MediaBrowser.MediaItem> children) {
    onMediaLoaded(children);
}
 
Example #29
Source File: MusicPlayerActivity.java    From android-music-player with Apache License 2.0 4 votes vote down vote up
public BrowseAdapter(Activity context) {
    super(context, R.layout.media_list_item, new ArrayList<MediaBrowser.MediaItem>());
}
 
Example #30
Source File: MusicPlayerActivity.java    From android-music-player with Apache License 2.0 4 votes vote down vote up
private void onMediaLoaded(List<MediaBrowser.MediaItem> media) {
    mBrowserAdapter.clear();
    mBrowserAdapter.addAll(media);
    mBrowserAdapter.notifyDataSetChanged();
}