Example usage for android.provider MediaStore UNKNOWN_STRING

List of usage examples for android.provider MediaStore UNKNOWN_STRING

Introduction

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

Prototype

String UNKNOWN_STRING

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

Click Source Link

Document

The string that is used when a media attribute is not known.

Usage

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

private void doSearch() {

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

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

    title = mCurrentTrackName;
    if (MediaStore.UNKNOWN_STRING.equals(mCurrentArtistNameForAlbum)) {
        query = mCurrentTrackName;
    } else {
        query = mCurrentArtistNameForAlbum + " " + mCurrentTrackName;
        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:com.android.music.TrackBrowserFragment.java

private void setTitle() {

    CharSequence fancyName = null;
    if (mAlbumId != null) {
        int numresults = mTrackCursor != null ? mTrackCursor.getCount() : 0;
        if (numresults > 0) {
            mTrackCursor.moveToFirst();/* w w  w  .j a v  a 2  s . c o  m*/
            int idx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
            fancyName = mTrackCursor.getString(idx);
            // For compilation albums show only the album title,
            // but for regular albums show "artist - album".
            // To determine whether something is a compilation
            // album, do a query for the artist + album of the
            // first item, and see if it returns the same number
            // of results as the album query.
            String where = MediaStore.Audio.Media.ALBUM_ID + "='" + mAlbumId + "' AND "
                    + MediaStore.Audio.Media.ARTIST_ID + "=" + mTrackCursor
                            .getLong(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST_ID));
            Cursor cursor = MusicUtils.query(getActivity(), MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    new String[] { MediaStore.Audio.Media.ALBUM }, where, null, null);
            if (cursor != null) {
                if (cursor.getCount() != numresults) {
                    // compilation album
                    fancyName = mTrackCursor.getString(idx);
                }
                cursor.deactivate();
            }
            if (fancyName == null || fancyName.equals(MediaStore.UNKNOWN_STRING)) {
                fancyName = getString(R.string.unknown_album_name);
            }
        }
    } else if (mPlaylist != null) {
        if (mPlaylist.equals("nowplaying")) {
            if (MusicUtils.getCurrentShuffleMode() == MediaPlaybackService.SHUFFLE_AUTO) {
                fancyName = getText(R.string.partyshuffle_title);
            } else {
                fancyName = getText(R.string.nowplaying_title);
            }
        } else if (mPlaylist.equals("podcasts")) {
            fancyName = getText(R.string.podcasts_title);
        } else if (mPlaylist.equals("recentlyadded")) {
            fancyName = getText(R.string.recentlyadded_title);
        } else {
            String[] cols = new String[] { MediaStore.Audio.Playlists.NAME };
            Cursor cursor = MusicUtils.query(getActivity(),
                    ContentUris.withAppendedId(Playlists.EXTERNAL_CONTENT_URI, Long.valueOf(mPlaylist)), cols,
                    null, null, null);
            if (cursor != null) {
                if (cursor.getCount() != 0) {
                    cursor.moveToFirst();
                    fancyName = cursor.getString(0);
                }
                cursor.deactivate();
            }
        }
    } else if (mGenre != null) {
        String[] cols = new String[] { MediaStore.Audio.Genres.NAME };
        Cursor cursor = MusicUtils.query(getActivity(),
                ContentUris.withAppendedId(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, Long.valueOf(mGenre)),
                cols, null, null, null);
        if (cursor != null) {
            if (cursor.getCount() != 0) {
                cursor.moveToFirst();
                fancyName = cursor.getString(0);
            }
            cursor.deactivate();
        }
    }

    if (fancyName != null) {
        getActivity().setTitle(fancyName);
    } else {
        getActivity().setTitle(R.string.tracks_title);
    }
}

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

private boolean isMusic(Cursor c) {
    int titleidx = c.getColumnIndex(MediaStore.Audio.Media.TITLE);
    int albumidx = c.getColumnIndex(MediaStore.Audio.Media.ALBUM);
    int artistidx = c.getColumnIndex(MediaStore.Audio.Media.ARTIST);

    String title = c.getString(titleidx);
    String album = c.getString(albumidx);
    String artist = c.getString(artistidx);
    if (MediaStore.UNKNOWN_STRING.equals(album) && MediaStore.UNKNOWN_STRING.equals(artist) && title != null
            && title.startsWith("recording")) {
        // not music
        return false;
    }//from  ww  w .  ja va 2 s.c  o  m

    int ismusic_idx = c.getColumnIndex(MediaStore.Audio.Media.IS_MUSIC);
    boolean ismusic = true;
    if (ismusic_idx >= 0) {
        ismusic = mTrackCursor.getInt(ismusic_idx) != 0;
    }
    return ismusic;
}

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

void doSearch() {
    CharSequence title = null;//from ww w .j ava 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 = mCurrentTrackName;
    if (MediaStore.UNKNOWN_STRING.equals(mCurrentArtistNameForAlbum)) {
        query = mCurrentTrackName;
    } else {
        query = mCurrentArtistNameForAlbum + " " + mCurrentTrackName;
        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.yammp.app.MusicPlaybackActivity.java

private void updateTrackInfo(boolean animation) {

    if (mService == null) {
        finish();/*  www.  j a v  a  2s.com*/
        return;
    }
    try {
        mTrackName.setText(mService.getTrackName());

        if (mService.getArtistName() != null && !MediaStore.UNKNOWN_STRING.equals(mService.getArtistName())) {
            mTrackDetail.setText(mService.getArtistName());
        } else if (mService.getAlbumName() != null
                && !MediaStore.UNKNOWN_STRING.equals(mService.getAlbumName())) {
            mTrackDetail.setText(mService.getAlbumName());
        } else {
            mTrackDetail.setText(R.string.unknown_artist);
        }

        if (mColorAnalyser != null) {
            mColorAnalyser.cancel(true);
        }
        mColorAnalyser = new AsyncColorAnalyser();
        mColorAnalyser.execute();

        mDuration = mService.duration();
        mTotalTime.setText(MusicUtils.makeTimeString(this, mDuration / 1000));
    } catch (RemoteException e) {
        e.printStackTrace();
        finish();
    }
}

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

private void updateTrackInfo(boolean animation) {

    if (mService == null) {
        finish();//from   w w  w. j a  va2s  .c o m
        return;
    }
    try {
        mTrackName.setText(mService.getTrackName());

        if (mService.getArtistName() != null && !MediaStore.UNKNOWN_STRING.equals(mService.getArtistName())) {
            mTrackDetail.setText(mService.getArtistName());
        } else if (mService.getAlbumName() != null
                && !MediaStore.UNKNOWN_STRING.equals(mService.getAlbumName())) {
            mTrackDetail.setText(mService.getAlbumName());
        } else {
            mTrackDetail.setText(R.string.unknown_artist);
        }

        if (mColorAnalyser != null)
            mColorAnalyser.cancel(true);
        mColorAnalyser = new AsyncColorAnalyser();
        mColorAnalyser.execute();

        mDuration = mService.duration();
        mTotalTime.setText(MusicUtils.makeTimeString(this, mDuration / 1000));
    } catch (RemoteException e) {
        e.printStackTrace();
        finish();
    }
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

static void updateNowPlaying(Activity a) {
    View nowPlayingView = a.findViewById(R.id.nowplaying);
    if (nowPlayingView == null) {
        return;/* w w  w .ja  v a  2  s .  c  om*/
    }
    boolean withtabs = false;
    Intent intent = a.getIntent();
    if (intent != null) {
        withtabs = intent.getBooleanExtra("withtabs", false);
    }
    //tinha um true == Music...
    if (MusicUtils.sService != null && MusicUtils.sService.getAudioId() != -1) {
        TextView title = (TextView) nowPlayingView.findViewById(R.id.title);
        TextView artist = (TextView) nowPlayingView.findViewById(R.id.artist);
        title.setText(MusicUtils.sService.getTrackName());
        String artistName = MusicUtils.sService.getArtistName();
        if (MediaStore.UNKNOWN_STRING.equals(artistName)) {
            artistName = a.getString(R.string.unknown_artist_name);
        }
        artist.setText(artistName);
        //mNowPlayingView.setOnFocusChangeListener(mFocuser);
        //mNowPlayingView.setOnClickListener(this);
        nowPlayingView.setVisibility(View.VISIBLE);
        nowPlayingView.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // Context c = v.getContext();
                // c.startActivity(new Intent(c, MediaPlaybackActivity.class));
            }
        });
        return;
    }
    nowPlayingView.setVisibility(View.GONE);
}

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

private void updateTrackInfo() {
    if (mService == null) {
        return;/* w  w  w  .  ja  v  a 2s.c  o m*/
    }
    try {
        String path = mService.getPath();
        if (path == null) {
            finish();
            return;
        }

        long songid = mService.getAudioId();
        if (songid < 0 && path.toLowerCase().startsWith("http://")) {
            // Once we can get album art and meta data from MediaPlayer, we
            // can show that info again when streaming.
            ((View) mArtistName.getParent()).setVisibility(View.INVISIBLE);
            ((View) mAlbumName.getParent()).setVisibility(View.INVISIBLE);
            mAlbum.setVisibility(View.GONE);
            mTrackName.setText(path);
            mAlbumArtHandler.removeMessages(GET_ALBUM_ART);
            mAlbumArtHandler.obtainMessage(GET_ALBUM_ART, new AlbumSongIdWrapper(-1, -1)).sendToTarget();
        } else {
            ((View) mArtistName.getParent()).setVisibility(View.VISIBLE);
            ((View) mAlbumName.getParent()).setVisibility(View.VISIBLE);
            String artistName = mService.getArtistName();
            if (MediaStore.UNKNOWN_STRING.equals(artistName)) {
                artistName = getString(R.string.unknown_artist_name);
            }
            mArtistName.setText(artistName);
            String albumName = mService.getAlbumName();
            long albumid = mService.getAlbumId();
            if (MediaStore.UNKNOWN_STRING.equals(albumName)) {
                albumName = getString(R.string.unknown_album_name);
                albumid = -1;
            }
            mAlbumName.setText(albumName);
            mTrackName.setText(mService.getTrackName());
            mAlbumArtHandler.removeMessages(GET_ALBUM_ART);
            mAlbumArtHandler.obtainMessage(GET_ALBUM_ART, new AlbumSongIdWrapper(albumid, songid))
                    .sendToTarget();
            mAlbum.setVisibility(View.VISIBLE);
        }
        mDuration = mService.duration();
        mTotalTime.setText(MusicUtils.makeTimeString(this, mDuration / 1000));
    } catch (RemoteException ex) {
        finish();
    }
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java

private void updateNotification() {
    RemoteViews views = new RemoteViews(getPackageName(), R.layout.statusbar);
    views.setImageViewResource(R.id.icon, R.drawable.stat_notify_musicplayer);
    if (getAudioId() < 0) {
        // streaming
        views.setTextViewText(R.id.trackname, getPath());
        views.setTextViewText(R.id.artistalbum, null);
    } else {//  w  w w. j a  v a  2 s  .c  o  m
        String artist = getArtistName();
        views.setTextViewText(R.id.trackname, getTrackName());
        if (artist == null || artist.equals(MediaStore.UNKNOWN_STRING)) {
            artist = getString(R.string.unknown_artist_name);
        }
        String album = getAlbumName();
        if (album == null || album.equals(MediaStore.UNKNOWN_STRING)) {
            album = getString(R.string.unknown_album_name);
        }

        views.setTextViewText(R.id.artistalbum, getString(R.string.notification_artist_album, artist, album));
    }
    Notification status = new Notification();
    status.contentView = views;
    status.flags |= Notification.FLAG_ONGOING_EVENT;
    status.icon = R.drawable.stat_notify_musicplayer;
    status.contentIntent = PendingIntent.getActivity(this, 0,
            new Intent("com.android.music.PLAYBACK_VIEWER").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0);
    startForeground(PLAYBACKSERVICE_STATUS, status);
}

From source file:org.yammp.MusicPlaybackService.java

/**
 * Starts playback of a previously opened file.
 *//*from  w  w  w  .  java 2  s.  c  o m*/
public void play() {

    CharSequence contentTitle, contentText = null;

    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK)
        return;

    mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);
    mAudioManager.registerMediaButtonEventReceiver(
            new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));

    telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

    if (mPlayer.isInitialized()) {
        // if we are at the end of the song, go to the next song first
        long duration = mPlayer.duration();
        if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) {
            next(true);
        }

        mPlayer.start();

        // make sure we fade in, in case a previous fadein was stopped
        // because
        // of another focus loss
        mMediaplayerHandler.removeMessages(FADEDOWN);
        mMediaplayerHandler.sendEmptyMessage(FADEUP);

        contentTitle = getTrackName();

        String artist = getArtistName();
        boolean isUnknownArtist = artist == null || MediaStore.UNKNOWN_STRING.equals(artist);

        String album = getAlbumName();
        boolean isUnknownAlbum = album == null || MediaStore.UNKNOWN_STRING.equals(album);

        if (!isUnknownArtist && !isUnknownAlbum) {
            contentText = getString(R.string.notification_artist_album, artist, album);
        } else if (isUnknownArtist && !isUnknownAlbum) {
            contentText = album;
        } else if (!isUnknownArtist && isUnknownAlbum) {
            contentText = artist;
        }

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(INTENT_PLAYBACK_VIEWER), 0);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setOngoing(true);
        builder.setSmallIcon(R.drawable.ic_stat_playback);
        builder.setContentIntent(contentIntent);
        builder.setContentTitle(contentTitle);
        builder.setContentText(contentText);
        mNotificationManager.notify(ID_NOTIFICATION_PLAYBACK, builder.getNotification());

        if (!mIsSupposedToBePlaying) {
            mIsSupposedToBePlaying = true;
            notifyChange(BROADCAST_PLAYSTATE_CHANGED);
        }

    } else if (mPlayListLen <= 0) {
        // This is mostly so that if you press 'play' on a bluetooth headset
        // without every having played anything before, it will still play
        // something.
        setShuffleMode(SHUFFLE_NORMAL);
    }
}