Example usage for android.provider MediaStore EXTRA_MEDIA_ARTIST

List of usage examples for android.provider MediaStore EXTRA_MEDIA_ARTIST

Introduction

In this page you can find the example usage for android.provider MediaStore EXTRA_MEDIA_ARTIST.

Prototype

String EXTRA_MEDIA_ARTIST

To view the source code for android.provider MediaStore EXTRA_MEDIA_ARTIST.

Click Source Link

Document

The name of the Intent-extra used to define the artist

Usage

From source file:org.musicmod.android.app.QueryFragment.java

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();//from w  ww . j a  va  2s  .com

    String action = bundle != null ? bundle.getString(INTENT_KEY_ACTION) : null;
    String data = bundle != null ? bundle.getString(INTENT_KEY_DATA) : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = Uri.parse(data);
        if (data.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            MusicUtils.playAll(getActivity(), list, 0);
            getActivity().finish();
            return;
        } else if (data.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            return;
        } else if (data.startsWith("content://media/external/audio/artists/")) {
            // This is an artist, show the albums for that artist
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
            i.putExtra("artist", uri.getLastPathSegment());
            startActivity(i);
            return;
        }
    }

    mFilterString = bundle != null ? bundle.getString(SearchManager.QUERY) : null;
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_FOCUS) : null;
        String artist = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ARTIST) : null;
        String album = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ALBUM) : null;
        String title = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_TITLE) : null;
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (Audio.Albums.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (Audio.Artists.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
}

From source file:com.andrew.apolloMod.activities.QueryBrowserActivity.java

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    if (mAdapter != null) {
        getQueryCursor(mAdapter.getQueryHandler(), null);
    }/*from  w w w .j  a  v a 2s .  com*/

    Intent intent = getIntent();
    String action = intent != null ? intent.getAction() : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = intent.getData();
        String path = uri.toString();
        if (path.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            MusicUtils.playAll(this, list, 0);
            finish();
            return;
        } else if (path.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            finish();
            return;
        } else if (path.startsWith("content://media/external/audio/artists/")) {
            intent = new Intent(Intent.ACTION_VIEW);

            Bundle bundle = new Bundle();
            bundle.putString(MIME_TYPE, Audio.Artists.CONTENT_TYPE);
            bundle.putString(ARTIST_KEY, uri.getLastPathSegment());
            bundle.putLong(BaseColumns._ID, ApolloUtils.getArtistId(uri.getLastPathSegment(), ARTIST_ID, this));

            intent.setClass(this, TracksBrowser.class);
            intent.putExtras(bundle);
            startActivity(intent);
            return;
        }
    }

    mFilterString = intent.getStringExtra(SearchManager.QUERY);
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = intent.getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS);
        String artist = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST);
        String album = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM);
        String title = intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE);
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (focus.equals(Audio.Albums.ENTRY_CONTENT_TYPE)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (focus.equals(Audio.Artists.ENTRY_CONTENT_TYPE)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    setContentView(R.layout.listview);
    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
    if (mAdapter == null) {
        mAdapter = new QueryListAdapter(getApplication(), this, R.layout.listview_items, null, // cursor
                new String[] {}, new int[] {}, 0);
        setListAdapter(mAdapter);
        if (TextUtils.isEmpty(mFilterString)) {
            getQueryCursor(mAdapter.getQueryHandler(), null);
        } else {
            mTrackList.setFilterText(mFilterString);
            mFilterString = null;
        }
    } else {
        mAdapter.setActivity(this);
        setListAdapter(mAdapter);
        mQueryCursor = mAdapter.getCursor();
        if (mQueryCursor != null) {
            init(mQueryCursor);
        } else {
            getQueryCursor(mAdapter.getQueryHandler(), mFilterString);
        }
    }

    LinearLayout emptyness = (LinearLayout) findViewById(R.id.empty_view);
    emptyness.setVisibility(View.GONE);
}

From source file:org.runbuddy.tomahawk.utils.MediaPlayIntentHandler.java

public void mediaPlayFromSearch(Bundle extras) {
    mWaitingGenre = null;/*from  w  w w.java 2 s  .  c  o  m*/
    mCorrespondingQueries.clear();
    mCorrespondingRequestIds.clear();
    mResolvingAlbum = null;
    mResolvingArtist = null;

    String mediaFocus = extras.getString(MediaStore.EXTRA_MEDIA_FOCUS);
    String query = extras.getString(SearchManager.QUERY);

    // Some of these extras may not be available depending on the search mode
    String album = extras.getString(MediaStore.EXTRA_MEDIA_ALBUM);
    String artist = extras.getString(MediaStore.EXTRA_MEDIA_ARTIST);
    final String genre = extras.getString("android.intent.extra.genre");
    String playlist = extras.getString("android.intent.extra.playlist");
    String title = extras.getString(MediaStore.EXTRA_MEDIA_TITLE);
    // Determine the search mode and use the corresponding extras
    if (mediaFocus == null) {
        // 'Unstructured' search mode (backward compatible)
        Query q = Query.get(query, false);
        mCorrespondingQueries.clear();
        mCorrespondingQueries.add(PipeLine.get().resolve(q));
    } else if (mediaFocus.compareTo("vnd.android.cursor.item/*") == 0) {
        if (query != null && query.isEmpty()) {
            // 'Any' search mode
            CollectionManager.get().getUserCollection().getQueries(Collection.SORT_ALPHA)
                    .done(new DoneCallback<Playlist>() {
                        @Override
                        public void onDone(Playlist collectionTracks) {
                            playPlaylist(collectionTracks, true);
                        }
                    });
        } else {
            // 'Unstructured' search mode
            Query q = Query.get(query, false);
            mCorrespondingQueries.add(PipeLine.get().resolve(q));
        }
    } else if (mediaFocus.compareTo(MediaStore.Audio.Genres.ENTRY_CONTENT_TYPE) == 0) {
        // 'Genre' search mode
        mWaitingGenre = genre;
        playGenre();
    } else if (mediaFocus.compareTo(MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE) == 0) {
        // 'Artist' search mode
        final Artist a = Artist.get(artist);
        CollectionManager.get().getUserCollection().getArtistTracks(a).done(new DoneCallback<Playlist>() {
            @Override
            public void onDone(Playlist result) {
                if (result != null && result.size() > 0) {
                    // There are some local tracks for the requested artist available
                    playPlaylist(result, false);
                } else {
                    // Try fetching top-hits for the requested artist
                    mResolvingArtist = a;
                    mCorrespondingRequestIds.add(InfoSystem.get().resolve(a, true));
                }
            }
        });
    } else if (mediaFocus.compareTo(MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE) == 0) {
        // 'Album' search mode
        final Album a = Album.get(album, Artist.get(artist));
        CollectionManager.get().getUserCollection().getAlbumTracks(a).done(new DoneCallback<Playlist>() {
            @Override
            public void onDone(Playlist result) {
                if (result != null && result.size() > 0) {
                    // There are some local tracks for the requested album available
                    playPlaylist(result, false);
                } else {
                    // Try fetching top-hits for the requested album
                    mResolvingAlbum = a;
                    mCorrespondingRequestIds.add(InfoSystem.get().resolve(a));
                }
            }
        });
    } else if (mediaFocus.compareTo("vnd.android.cursor.item/audio") == 0) {
        // 'Song' search mode
        Query q = Query.get(title, album, artist, false);
        mCorrespondingQueries.add(PipeLine.get().resolve(q));
    } else if (mediaFocus.compareTo(MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE) == 0) {
        // 'Playlist' search mode
        Playlist bestMatch = null;
        float bestScore = 0f;
        float minScore = 0.7f;
        for (Playlist pl : DatabaseHelper.get().getPlaylists()) {
            float score = ResultScoring.calculateScore(pl.getName(), playlist);
            if (score > minScore && score > bestScore) {
                bestMatch = pl;
                bestScore = score;
            }
        }
        if (bestMatch != null) {
            playPlaylist(bestMatch, false);
        }
    }
}

From source file:util.mediamanager.PlaylistUtils.java

public static void PlaySearchArtist(Context context, String artist) {
    Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
    intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);
    intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    intent.putExtra(SearchManager.QUERY, artist);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);// ww w .ja  va2  s.  c o m
    }
}

From source file:org.yammp.fragment.QueryFragment.java

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();//w  w w . j  a va2  s .  c  o  m

    String action = bundle != null ? bundle.getString(INTENT_KEY_ACTION) : null;
    String data = bundle != null ? bundle.getString(INTENT_KEY_DATA) : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = Uri.parse(data);
        if (data.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            mUtils.playAll(list, 0);
            getActivity().finish();
            return;
        } else if (data.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            return;
        } else if (data.startsWith("content://media/external/audio/artists/")) {
            // This is an artist, show the albums for that artist
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
            i.putExtra("artist", uri.getLastPathSegment());
            startActivity(i);
            return;
        }
    }

    mFilterString = bundle != null ? bundle.getString(SearchManager.QUERY) : null;
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_FOCUS) : null;
        String artist = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ARTIST) : null;
        String album = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ALBUM) : null;
        String title = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_TITLE) : null;
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (Audio.Albums.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (Audio.Artists.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
}

From source file:org.yammp.app.AlbumFragment.java

private void doSearch() {

    CharSequence title = null;/*w w w.  java  2 s .  com*/
    String query = null;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    title = mCurrentAlbumName;
    if (MediaStore.UNKNOWN_STRING.equals(mCurrentArtistNameForAlbum)) {
        query = mCurrentAlbumName;
    } else {
        query = mCurrentArtistNameForAlbum + " " + mCurrentAlbumName;
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistNameForAlbum);
    }
    if (MediaStore.UNKNOWN_STRING.equals(mCurrentAlbumName)) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, mCurrentAlbumName);
    }
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}

From source file:org.peterbaldwin.vlcremote.fragment.PlaylistFragment.java

private void searchForItem(PlaylistItem item) {
    if (item instanceof Track) {
        Track track = (Track) item;
        String title = track.getTitle();
        String artist = track.getArtist();
        String query = artist + " " + title;

        Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
        intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
        intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, title);
        intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
        intent.putExtra(SearchManager.QUERY, query);

        String chooserTitle = getString(R.string.mediasearch, title);
        startActivity(Intent.createChooser(intent, chooserTitle));
    }/*from   w w  w  .  j a  v  a2 s. c o m*/
}

From source file:org.yammp.app.ArtistFragment.java

private void doSearch() {

    CharSequence title = null;/*from ww w .  j a v  a  2  s . co m*/
    String query = null;

    if (mCurrentGroupArtistName == null || MediaStore.UNKNOWN_STRING.equals(mCurrentGroupArtistName))
        return;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    title = mCurrentGroupArtistName;

    query = mCurrentGroupArtistName;
    i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentGroupArtistName);
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}

From source file:com.android.music.ArtistAlbumBrowserFragment.java

void doSearch() {
    CharSequence title = null;/*from   w ww.j a  v a 2 s . co  m*/
    String query = null;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (mCurrentArtistId != null) {
        title = mCurrentArtistName;
        query = mCurrentArtistName;
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistName);
        i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE);
    } else {
        if (mIsUnknownAlbum) {
            title = query = mCurrentArtistNameForAlbum;
        } else {
            title = query = mCurrentAlbumName;
            if (!mIsUnknownArtist) {
                query = query + " " + mCurrentArtistNameForAlbum;
            }
        }
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, mCurrentArtistNameForAlbum);
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, mCurrentAlbumName);
        i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE);
    }
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}

From source file:org.yammp.fragment.ArtistFragment.java

private void doSearch(String artist, String album) {

    CharSequence title = null;//www  .  j a v a 2s  .  c om
    String query = null;

    boolean isUnknownArtist = artist == null || MediaStore.UNKNOWN_STRING.equals(artist);
    boolean isUnknownAlbum = album == null || MediaStore.UNKNOWN_STRING.equals(album);
    if (isUnknownArtist && isUnknownAlbum)
        return;

    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    title = album != null ? album : artist;
    query = album != null ? album : artist;

    if (!isUnknownArtist) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    }
    if (!isUnknownAlbum) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
    }
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    title = getString(R.string.mediasearch, title);
    i.putExtra(SearchManager.QUERY, query);

    startActivity(Intent.createChooser(i, title));
}