本文整理汇总了Java中android.media.MediaMetadata.getString方法的典型用法代码示例。如果您正苦于以下问题:Java MediaMetadata.getString方法的具体用法?Java MediaMetadata.getString怎么用?Java MediaMetadata.getString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaMetadata
的用法示例。
在下文中一共展示了MediaMetadata.getString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCustomAction
import android.media.MediaMetadata; //导入方法依赖的package包/类
@Override
public void onCustomAction(@NonNull String action, Bundle extras) {
if (CUSTOM_ACTION_THUMBS_UP.equals(action)) {
LogHelper.i(TAG, "onCustomAction: favorite for current track");
MediaMetadata track = getCurrentPlayingMusic();
if (track != null) {
String musicId = track.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
mMusicProvider.setFavorite(musicId, !mMusicProvider.isFavorite(musicId));
}
// playback state needs to be updated because the "Favorite" icon on the
// custom action will change to reflect the new favorite state.
updatePlaybackState(null);
} else {
LogHelper.e(TAG, "Unsupported action: ", action);
}
}
示例2: setCustomAction
import android.media.MediaMetadata; //导入方法依赖的package包/类
private void setCustomAction(PlaybackState.Builder stateBuilder) {
MediaMetadata currentMusic = getCurrentPlayingMusic();
if (currentMusic != null) {
// Set appropriate "Favorite" icon on Custom action:
String musicId = currentMusic.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
int favoriteIcon = R.drawable.ic_star_off;
if (mMusicProvider.isFavorite(musicId)) {
favoriteIcon = R.drawable.ic_star_on;
}
LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ",
musicId, " current favorite=", mMusicProvider.isFavorite(musicId));
Bundle customActionExtras = new Bundle();
WearHelper.setShowCustomActionOnWear(customActionExtras, true);
stateBuilder.addCustomAction(new PlaybackState.CustomAction.Builder(
CUSTOM_ACTION_THUMBS_UP, getString(R.string.favorite), favoriteIcon)
.setExtras(customActionExtras)
.build());
}
}
示例3: updateMusic
import android.media.MediaMetadata; //导入方法依赖的package包/类
public synchronized void updateMusic(String musicId, MediaMetadata metadata) {
MutableMediaMetadata track = mMusicListById.get(musicId);
if (track == null) {
return;
}
String oldGenre = track.metadata.getString(MediaMetadata.METADATA_KEY_GENRE);
String newGenre = metadata.getString(MediaMetadata.METADATA_KEY_GENRE);
track.metadata = metadata;
// if genre has changed, we need to rebuild the list by genre
if (!oldGenre.equals(newGenre)) {
buildListsByGenre();
}
}
示例4: onCustomAction
import android.media.MediaMetadata; //导入方法依赖的package包/类
@Override
public void onCustomAction(String action, Bundle extras) {
if (CUSTOM_ACTION_THUMBS_UP.equals(action)) {
LogHelper.i(TAG, "onCustomAction: favorite for current track");
MediaMetadata track = getCurrentPlayingMusic();
if (track != null) {
String musicId = track.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
mMusicProvider.setFavorite(musicId, !mMusicProvider.isFavorite(musicId));
}
// playback state needs to be updated because the "Favorite" icon on the
// custom action will change to reflect the new favorite state.
updatePlaybackState(null);
} else {
LogHelper.e(TAG, "Unsupported action: ", action);
}
}
示例5: onCustomAction
import android.media.MediaMetadata; //导入方法依赖的package包/类
@Override
public void onCustomAction(String action, Bundle extras) {
if (CUSTOM_ACTION_THUMBS_UP.equals(action)) {
LogHelper.i(TAG, "onCustomAction: favorite for current track");
MediaMetadata track = getCurrentPlayingMusic();
if (track != null) {
String musicId = track.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
mMusicProvider.setFavorite(musicId, !mMusicProvider.isFavorite(musicId));
}
// playback state needs to be updated because the "Favorite" icon on the
// custom action will change to reflect the new favorite state.
updatePlaybackState(null);
} else {
LogHelper.e(TAG, "Unsupported action: ", action);
}
}
示例6: updateMusic
import android.media.MediaMetadata; //导入方法依赖的package包/类
public synchronized void updateMusic(String musicId, MediaMetadata metadata) {
MutableMediaMetadata track = mMusicListById.get(musicId);
if (track == null) {
return;
}
String oldGenre = track.metadata.getString(MediaMetadata.METADATA_KEY_GENRE);
String newGenre = metadata.getString(MediaMetadata.METADATA_KEY_GENRE);
track.metadata = metadata;
// if genre has changed, we need to rebuild the list by genre
if (!oldGenre.equals(newGenre)) {
buildListsByGenre();
}
}
示例7: retrieveMedia
import android.media.MediaMetadata; //导入方法依赖的package包/类
private synchronized void retrieveMedia() {
try {
if (mCurrentState == State.NON_INITIALIZED) {
mCurrentState = State.INITIALIZING;
int slashPos = CATALOG_URL.lastIndexOf('/');
String path = CATALOG_URL.substring(0, slashPos + 1);
JSONObject jsonObj = fetchJSONFromUrl(CATALOG_URL);
if (jsonObj == null) {
return;
}
JSONArray tracks = jsonObj.getJSONArray(JSON_MUSIC);
if (tracks != null) {
for (int j = 0; j < tracks.length(); j++) {
MediaMetadata item = buildFromJSON(tracks.getJSONObject(j), path);
String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item));
}
buildListsByGenre();
}
mCurrentState = State.INITIALIZED;
}
} catch (JSONException e) {
LogHelper.e(TAG, e, "Could not retrieve music list");
} finally {
if (mCurrentState != State.INITIALIZED) {
// Something bad happened, so we reset state to NON_INITIALIZED to allow
// retries (eg if the network connection is temporary unavailable)
mCurrentState = State.NON_INITIALIZED;
}
}
}
示例8: setCustomAction
import android.media.MediaMetadata; //导入方法依赖的package包/类
private void setCustomAction(PlaybackState.Builder stateBuilder) {
MediaMetadata currentMusic = getCurrentPlayingMusic();
if (currentMusic != null) {
// Set appropriate "Favorite" icon on Custom action:
String musicId = currentMusic.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
int favoriteIcon = R.drawable.ic_star_off;
if (mMusicProvider.isFavorite(musicId)) {
favoriteIcon = R.drawable.ic_star_on;
}
LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ",
musicId, " current favorite=", mMusicProvider.isFavorite(musicId));
stateBuilder.addCustomAction(CUSTOM_ACTION_THUMBS_UP, getString(R.string.favorite),
favoriteIcon);
}
}
示例9: retrieveMedia
import android.media.MediaMetadata; //导入方法依赖的package包/类
private synchronized void retrieveMedia() {
try {
if (mCurrentState == State.NON_INITIALIZED) {
mCurrentState = State.INITIALIZING;
JSONObject jsonObj = MusicAPI.getPlaylistDetails("60198");
if (jsonObj == null) {
return;
}
JSONArray tracks = jsonObj.getJSONArray(JSON_TRACKS);
if (tracks != null) {
for (int j = 0; j < 20; j++) {
MediaMetadata item = buildFromJSON(tracks.getJSONObject(j));
String musicId = item.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
mMusicListById.put(musicId, new MutableMediaMetadata(musicId, item));
}
buildListsByGenre();
}
mCurrentState = State.INITIALIZED;
}
} catch (JSONException e) {
e.printStackTrace();
} finally {
if (mCurrentState != State.INITIALIZED) {
// Something bad happened, so we reset state to NON_INITIALIZED to allow
// retries (eg if the network connection is temporary unavailable)
mCurrentState = State.NON_INITIALIZED;
}
}
}
示例10: getMediaTitle
import android.media.MediaMetadata; //导入方法依赖的package包/类
@Override
public CharSequence getMediaTitle() {
MediaMetadata mediaMetadata = mMediaController.getMetadata();
return mediaMetadata == null ? ""
: mediaMetadata.getString(MediaMetadata.METADATA_KEY_TITLE);
}
示例11: getMediaSubtitle
import android.media.MediaMetadata; //导入方法依赖的package包/类
@Override
public CharSequence getMediaSubtitle() {
MediaMetadata mediaMetadata = mMediaController.getMetadata();
return mediaMetadata == null ? ""
: mediaMetadata.getString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE);
}
示例12: fromMediaMetadata
import android.media.MediaMetadata; //导入方法依赖的package包/类
public static Track fromMediaMetadata(MediaMetadata metadata) {
String title = metadata.getString(MediaMetadata.METADATA_KEY_TITLE);
String artist = metadata.getString(MediaMetadata.METADATA_KEY_ARTIST);
String album = metadata.getString(MediaMetadata.METADATA_KEY_ALBUM);
String albumArtist = metadata.getString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST);
Bitmap art = metadata.getBitmap(MediaMetadata.METADATA_KEY_ART);
long duration = metadata.getLong(MediaMetadata.METADATA_KEY_DURATION);
if (title == null) {
title = metadata.getString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE);
if (title == null) {
title = "";
}
}
if (art == null) {
art = metadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
}
Track.Builder builder = Track.builder().track(title);
if (duration < 1000) {
// Apple Music incorrectly reports durations in seconds instead of ms (when it reports
// duration at all).
duration *= 1000;
}
if (duration > 0) {
builder.duration(duration);
}
if (album != null && !album.isEmpty()) {
builder.album(album);
}
if (albumArtist != null && !albumArtist.isEmpty()) {
builder.albumArtist(albumArtist);
}
if (art != null) {
builder.art(art);
}
if (artist != null) {
builder.artist(artist);
} else if (albumArtist != null) {
// Some apps (Telegram) set ALBUM_ARTIST but not ARTIST.
builder.artist(albumArtist);
} else {
return new TitleExtractor().transform(builder.artist("").build());
}
return builder.build();
}
示例13: play
import android.media.MediaMetadata; //导入方法依赖的package包/类
@Override
public void play(QueueItem item) {
mPlayOnFocusGain = true;
tryToGetAudioFocus();
registerAudioNoisyReceiver();
String mediaId = item.getDescription().getMediaId();
boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
if (mediaHasChanged) {
mCurrentPosition = 0;
mCurrentMediaId = mediaId;
}
if (mState == PlaybackState.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
configMediaPlayerState();
} else {
mState = PlaybackState.STATE_STOPPED;
relaxResources(false); // release everything except MediaPlayer
MediaMetadata track = mMusicProvider.getMusic(
MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId()));
String source = track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE);
try {
createMediaPlayerIfNeeded();
mState = PlaybackState.STATE_BUFFERING;
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setDataSource(source);
// Starts preparing the media player in the background. When
// it's done, it will call our OnPreparedListener (that is,
// the onPrepared() method on this class, since we set the
// listener to 'this'). Until the media player is prepared,
// we *cannot* call start() on it!
mMediaPlayer.prepareAsync();
// If we are streaming from the internet, we want to hold a
// Wifi lock, which prevents the Wifi radio from going to
// sleep while the song is playing.
mWifiLock.acquire();
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
} catch (IOException ex) {
LogHelper.e(TAG, ex, "Exception playing song");
if (mCallback != null) {
mCallback.onError(ex.getMessage());
}
}
}
}