Example usage for android.provider MediaStore INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH

List of usage examples for android.provider MediaStore INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH

Introduction

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

Prototype

String INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH

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

Click Source Link

Document

An intent to perform a search for music media and automatically play content from the result when possible.

Usage

From source file:com.example.chu.googleplaylibrary.ui.MusicPlayerActivity.java

protected void initializeFromParams(Bundle savedInstanceState, Intent intent) {
    String mediaId = null;/*w w w . j a  v  a2s  .  c o m*/
    // check if we were started from a "Play XYZ" voice search. If so, we save the extras
    // (which contain the query details) in a parameter, so we can reuse it later, when the
    // MediaSession is connected.
    if (intent.getAction() != null
            && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
        mVoiceSearchParams = intent.getExtras();
        LogHelper.d(TAG, "Starting from voice search query=",
                mVoiceSearchParams.getString(SearchManager.QUERY));
    } else {
        if (savedInstanceState != null) {
            // If there is a saved media ID, use it
            mediaId = savedInstanceState.getString(SAVED_MEDIA_ID);
        }
    }
}

From source file:com.classiqo.nativeandroid_32bitz.ui.MusicPlayerActivity.java

protected void initializeFromParams(Bundle savedInstanceState, Intent intent) {
    String mediaId = null;//from   w  w  w.  ja  va  2 s. co m

    if (intent.getAction() != null
            && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
        mVoiceSearchParams = intent.getExtras();
        LogHelper.d(TAG, "Starting from voice search query = ",
                mVoiceSearchParams.getString(SearchManager.QUERY));
    } else {
        if (savedInstanceState != null) {
            mediaId = savedInstanceState.getString(SAVED_MEDIA_ID);
        }
    }
    navigateToBrowser(mediaId);
}

From source file:com.example.android.AudioArchive.ui.MusicPlayerActivity.java

protected void initializeFromParams(Bundle savedInstanceState, Intent intent) {
    String mediaId = null;//  w ww.  j a  v  a 2s . c  om
    // check if we were started from a "Play XYZ" voice search. If so, we save the extras
    // (which contain the query details) in a parameter, so we can reuse it later, when the
    // MediaSession is connected.
    if (intent.getAction() != null
            && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
        mVoiceSearchParams = intent.getExtras();
        LogHelper.d(TAG, "Starting from voice search query=",
                mVoiceSearchParams.getString(SearchManager.QUERY));
    } else {
        if (savedInstanceState != null) {
            // If there is a saved media ID, use it
            mediaId = savedInstanceState.getString(SAVED_MEDIA_ID);
        }
    }
    navigateToBrowser(mediaId);
}

From source file:com.phearom.um.ui.MusicPlayerActivity.java

protected void initializeFromParams(Bundle savedInstanceState, Intent intent) {
    String mediaId = null;//from  w  w  w.  j a  va 2  s  .c  om
    if (intent.getAction() != null
            && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
        mVoiceSearchParams = intent.getExtras();
        LogHelper.d(TAG, "Starting from voice search query=",
                mVoiceSearchParams.getString(SearchManager.QUERY));
    } else {
        if (savedInstanceState != null) {
            mediaId = savedInstanceState.getString(SAVED_MEDIA_ID);
        }
    }
    navigateToBrowser(mediaId);
}

From source file:com.scooter1556.sms.android.activity.HomeActivity.java

protected void initialiseFromParams(Bundle savedInstanceState, Intent intent) {
    // check if we were started from a "Play XYZ" voice search. If so, we save the extras
    // (which contain the query details) in a parameter, so we can reuse it later, when the
    // MediaSession is connected.
    if (intent.getAction() != null
            && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
        voiceSearchParams = intent.getExtras();
        Log.d(TAG, "Starting from voice search query=" + voiceSearchParams.getString(SearchManager.QUERY));
    }/*from   w w  w .ja  v  a  2 s.  c om*/
}

From source file:com.bayapps.android.robophish.ui.MusicPlayerActivity.java

protected void initializeFromParams(Bundle savedInstanceState, Intent intent) {
    String mediaId = null;//from  w  ww.  ja v  a2  s  .co  m
    // check if we were started from a "Play XYZ" voice search. If so, we save the extras
    // (which contain the query details) in a parameter, so we can reuse it later, when the
    // MediaSession is connected.
    if (intent.getAction() != null
            && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
        mVoiceSearchParams = intent.getExtras();
        LogHelper.d(TAG, "Starting from voice search query=",
                mVoiceSearchParams.getString(SearchManager.QUERY));
    } else if (intent.getAction() != null && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_SEARCH)) {

        navigateToBrowser(null, null, null);

        Bundle extras = intent.getExtras();
        String title = extras.getString("title");
        String subtitle = extras.getString("subtitle");
        mediaId = extras.getString("showid");

        String year = subtitle.split("-")[0];
        //browse to year...
        navigateToBrowser(null, null, MediaIDHelper.MEDIA_ID_SHOWS_BY_YEAR + "/" + year);

        //now launch as show
        navigateToBrowser(title, subtitle, mediaId);
    }

    else {
        if (savedInstanceState != null) {
            // If there is a saved media ID, use it
            mediaId = savedInstanceState.getString(SAVED_MEDIA_ID);
        }
        navigateToBrowser(null, null, mediaId);
    }
}

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);//w  ww  .ja  v  a 2 s  .  c om
    }
}

From source file:util.mediamanager.PlaylistUtils.java

public static void PlayGMPlaylistUsingSearch(Context context, String playlist) {
    Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
    intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE);
    intent.putExtra(SearchManager.QUERY, playlist);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);/*from  ww  w.j  a  va2s. c  o m*/
    }
}

From source file:nuclei.media.MediaInterface.java

void onConnected() {
    try {/*from  w  w w .j ava2 s .c o  m*/
        Context context = mFragmentActivity == null ? mLActivity : mFragmentActivity;
        if (context == null)
            return;
        mMediaControls = new MediaControllerCompat(context, mMediaBrowser.getSessionToken());
        mMediaCallback = new MediaControllerCompat.Callback() {
            @Override
            public void onPlaybackStateChanged(PlaybackStateCompat state) {
                MediaInterface.this.onPlaybackStateChanged(state);
            }

            @Override
            public void onSessionEvent(String event, Bundle extras) {
                MediaInterface.this.onSessionEvent(event, extras);
            }

            @Override
            public void onMetadataChanged(MediaMetadataCompat metadata) {
                MediaInterface.this.onMetadataChanged(metadata);
            }
        };
        mMediaControls.registerCallback(mMediaCallback);

        if (mFragmentActivity != null) {
            MediaControllerCompat.setMediaController(mFragmentActivity, mMediaControls);
            //mFragmentActivity.setSupportMediaController(mMediaControls);
        } else if (mLActivity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            setMediaControllerL();

        if (mPlayerControls != null)
            mPlayerControls.setMediaControls(mCallbacks, mMediaControls);

        if (mMediaControls.getPlaybackState() != null)
            onPlaybackStateChanged(mMediaControls.getPlaybackState());

        final Intent intent = mFragmentActivity == null ? mLActivity.getIntent()
                : mFragmentActivity.getIntent();
        if (MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH.equals(intent.getAction())) {
            final Bundle params = intent.getExtras();
            final String query = params.getString(SearchManager.QUERY);
            LOG.i("Starting from voice search query=" + query);
            mMediaControls.getTransportControls().playFromSearch(query, params);
        }
        if (mCallbacks != null) {
            mCallbacks.onConnected(this);
            MediaMetadataCompat metadataCompat = mMediaControls.getMetadata();
            if (metadataCompat != null) {
                final long duration = metadataCompat.getLong(MediaMetadataCompat.METADATA_KEY_DURATION);
                if (duration > 0)
                    mCallbacks.setTimeTotal(this, duration);
            }
        }

        Bundle extras = mMediaControls.getExtras();
        if (extras != null && extras.containsKey(MediaService.EXTRA_CONNECTED_CAST)) {
            mCallbacks.onCasting(this, extras.getString(MediaService.EXTRA_CONNECTED_CAST));
        }

        if (mPlayerControls != null && mPlayerControls.isPlaying())
            mHandler.start();

        if (mSurface != null)
            setSurface(mSurface);

        LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(ACTION_CONNECTED));
    } catch (RemoteException err) {
        LOG.e("Error in onConnected", err);
    }
}

From source file:com.murati.oszk.audiobook.ui.MusicPlayerActivity.java

protected void initializeFromParams(Bundle savedInstanceState, Intent intent) {
    String mediaId = null;/*from ww  w. ja v a 2s . c  o  m*/

    String action = intent.getAction();
    Bundle extras = intent.getExtras();

    if (action != null) {
        switch (action) {
        case Intent.ACTION_SEARCH:
        case MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH:
            LogHelper.d(TAG, "Starting Search Handler");
            mSearchParams = intent.getExtras();

            mediaId = MediaIDHelper.createMediaID(mSearchParams.getString(SearchManager.QUERY),
                    MediaIDHelper.MEDIA_ID_BY_SEARCH);

            LogHelper.d(TAG, "Search query=", mediaId);
            break;

        case Intent.ACTION_VIEW:
            if (extras != null)
                mediaId = extras.getString(MediaIDHelper.EXTRA_MEDIA_ID_KEY);
            LogHelper.d(TAG, "MediaId fetched=", mediaId);
            break;

        case Intent.ACTION_MAIN:
        default:
            break;
        }
    } else {
        if (savedInstanceState != null) {
            // If there is a saved media ID, use it
            mediaId = savedInstanceState.getString(MediaIDHelper.EXTRA_MEDIA_ID_KEY);
        }
    }
    navigateToBrowser(mediaId);
}