Example usage for android.provider MediaStore EXTRA_MEDIA_TITLE

List of usage examples for android.provider MediaStore EXTRA_MEDIA_TITLE

Introduction

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

Prototype

String EXTRA_MEDIA_TITLE

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

Click Source Link

Document

The name of the Intent-extra used to define the song title

Usage

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

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();// ww w . ja  v  a  2  s. co  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) };
            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);
    }/*w w w  .j a  v a 2  s .c  om*/

    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;/*www .  j  av a  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:org.yammp.fragment.QueryFragment.java

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();//  w w  w .j ava2  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.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));
    }//  w  ww.  j  a  va 2 s .co m
}

From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java

public void takePicture() {
    if (!canSetPhoto()) {
        return;/* w  w w .j a  va2s .  c  o  m*/
    }

    if (isMyDataIncomplete()) {
        checkMyData();
    } else {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File file = getCameraMediaFile();
        if (file != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "de.bahnhoefe.deutschlands.bahnhofsfotos.fileprovider", file);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            intent.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, getResources().getString(R.string.app_name));
            intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, bahnhof.getTitle());
            intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            startActivityForResult(intent, REQUEST_TAKE_PICTURE);
        } else {
            Toast.makeText(this, R.string.unable_to_create_folder_structure, Toast.LENGTH_LONG).show();
        }
    }
}

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

@Override
public boolean onLongClick(View v) {

    // TODO search media info

    String track = getTitle().toString();
    String artist = "";// mArtistNameView.getText().toString();
    String album = "";// mAlbumNameView.getText().toString();

    CharSequence title = getString(R.string.mediasearch, track);
    Intent i = new Intent();
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.putExtra(MediaStore.EXTRA_MEDIA_TITLE, track);

    String query = track;// w  w w .  j  a  v  a  2 s .  c  om
    if (!getString(R.string.unknown_artist).equals(artist)
            && !getString(R.string.unknown_album).equals(album)) {
        query = artist + " " + track;
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    } else if (getString(R.string.unknown_artist).equals(artist)
            && !getString(R.string.unknown_album).equals(album)) {
        query = album + " " + track;
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
    } else if (!getString(R.string.unknown_artist).equals(artist)
            && getString(R.string.unknown_album).equals(album)) {
        query = artist + " " + track;
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    }
    i.putExtra(SearchManager.QUERY, query);
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    startActivity(Intent.createChooser(i, title));
    return true;
}

From source file:org.mariotaku.harmony.activity.MusicPlaybackActivity.java

public boolean onLongClick(final View v) {

    // TODO search media info

    String track = getTitle().toString();
    String artist = "";// mArtistNameView.getText().toString();
    String album = "";// mAlbumNameView.getText().toString();

    CharSequence title = getString(R.string.mediasearch, track);
    Intent i = new Intent();
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.putExtra(MediaStore.EXTRA_MEDIA_TITLE, track);

    String query = track;//  www .  j  a v a  2 s  . c  o m
    if (!getString(R.string.unknown_artist).equals(artist)
            && !getString(R.string.unknown_album).equals(album)) {
        query = artist + " " + track;
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    } else if (getString(R.string.unknown_artist).equals(artist)
            && !getString(R.string.unknown_album).equals(album)) {
        query = album + " " + track;
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
    } else if (!getString(R.string.unknown_artist).equals(artist)
            && getString(R.string.unknown_album).equals(album)) {
        query = artist + " " + track;
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    }
    i.putExtra(SearchManager.QUERY, query);
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "audio/*");
    startActivity(Intent.createChooser(i, title));
    return true;
}

From source file:github.popeen.dsub.activity.SubsonicFragmentActivity.java

@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    if (currentFragment != null && intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) {
        if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
            closeNowPlaying();/*from  w w w .j  a  va  2  s  . c  o  m*/
        }

        if (currentFragment instanceof SearchFragment) {
            String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY);
            boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
            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 (query != null) {
                ((SearchFragment) currentFragment).search(query, autoplay, artist, album, title);
            }
            getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_QUERY);
        } else {
            setIntent(intent);

            SearchFragment fragment = new SearchFragment();
            replaceFragment(fragment, fragment.getSupportTag());
        }
    } else if (intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, false)) {
        if (slideUpPanel.getPanelState() != SlidingUpPanelLayout.PanelState.EXPANDED) {
            openNowPlaying();
        }
    } else {
        if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
            closeNowPlaying();
        }
        setIntent(intent);
    }
    if (drawer != null) {
        drawer.closeDrawers();
    }
}

From source file:com.android.app.MediaPlaybackActivity.java

public boolean onLongClick(View view) {

    CharSequence title = null;//  ww  w  .  ja v a  2 s.  com
    String mime = null;
    String query = null;
    String artist;
    String album;
    String song;
    long audioid;

    try {
        artist = mService.getArtistName();
        album = mService.getAlbumName();
        song = mService.getTrackName();
        audioid = mService.getAudioId();
    } catch (RemoteException ex) {
        return true;
    } catch (NullPointerException ex) {
        // we might not actually have the service yet
        return true;
    }

    if (MediaStore.UNKNOWN_STRING.equals(album) && MediaStore.UNKNOWN_STRING.equals(artist) && song != null
            && song.startsWith("recording")) {
        // not music
        return false;
    }

    if (audioid < 0) {
        return false;
    }

    Cursor c = MusicUtils.query(this,
            ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, audioid),
            new String[] { MediaStore.Audio.Media.IS_MUSIC }, null, null, null);
    boolean ismusic = true;
    if (c != null) {
        if (c.moveToFirst()) {
            ismusic = c.getInt(0) != 0;
        }
        c.close();
    }
    if (!ismusic) {
        return false;
    }

    boolean knownartist = (artist != null) && !MediaStore.UNKNOWN_STRING.equals(artist);

    boolean knownalbum = (album != null) && !MediaStore.UNKNOWN_STRING.equals(album);

    if (knownartist && view.equals(mArtistName.getParent())) {
        title = artist;
        query = artist;
        mime = MediaStore.Audio.Artists.ENTRY_CONTENT_TYPE;
    } else if (knownalbum && view.equals(mAlbumName.getParent())) {
        title = album;
        if (knownartist) {
            query = artist + " " + album;
        } else {
            query = album;
        }
        mime = MediaStore.Audio.Albums.ENTRY_CONTENT_TYPE;
    } else if (view.equals(mTrackName.getParent()) || !knownartist || !knownalbum) {
        if ((song == null) || MediaStore.UNKNOWN_STRING.equals(song)) {
            // A popup of the form "Search for null/'' using ..." is pretty
            // unhelpful, plus, we won't find any way to buy it anyway.
            return true;
        }

        title = song;
        if (knownartist) {
            query = artist + " " + song;
        } else {
            query = song;
        }
        mime = "audio/*"; // the specific type doesn't matter, so don't bother retrieving it
    } else {
        throw new RuntimeException("shouldn't be here");
    }
    title = getString(R.string.mediasearch, title);

    Intent i = new Intent();
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.putExtra(SearchManager.QUERY, query);
    if (knownartist) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
    }
    if (knownalbum) {
        i.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
    }
    i.putExtra(MediaStore.EXTRA_MEDIA_TITLE, song);
    i.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, mime);

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