use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class PlaylistActivity method handleContextItemSelected.
protected boolean handleContextItemSelected(MenuItem item, final int position) {
int id = item.getItemId();
final MediaWrapper media = (MediaWrapper) mAdapter.getItem(position);
if (id == R.id.audio_list_browser_set_song) {
AudioUtil.setRingtone(media, this);
return true;
} else if (id == R.id.audio_list_browser_append) {
mService.append(media);
return true;
} else if (id == R.id.audio_list_browser_insert_next) {
mService.insertNext(media);
return true;
} else if (id == R.id.audio_list_browser_delete) {
mAdapter.remove(media);
final Runnable cancel = new Runnable() {
@Override
public void run() {
mAdapter.addItems(media);
}
};
UiTools.snackerWithCancel(mBinding.getRoot(), getString(R.string.file_deleted), new Runnable() {
@Override
public void run() {
if (mIsPlaylist)
((Playlist) mPlaylist).remove(media.getId());
else
deleteMedia(media, cancel);
}
}, cancel);
return true;
} else if (id == R.id.audio_view_info) {
showInfoDialog(media);
return true;
} else if (id == R.id.audio_view_add_playlist) {
FragmentManager fm = getSupportFragmentManager();
SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
Bundle args = new Bundle();
args.putParcelableArray(SavePlaylistDialog.KEY_NEW_TRACKS, media.getTracks());
savePlaylistDialog.setArguments(args);
savePlaylistDialog.show(fm, "fragment_add_to_playlist");
return true;
}
return false;
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class PlaybackService method updateMediaQueue.
private void updateMediaQueue() {
final LinkedList<MediaSessionCompat.QueueItem> queue = new LinkedList<>();
long position = -1;
for (MediaWrapper media : playlistManager.getMediaList()) {
String title = media.getNowPlaying();
if (title == null)
title = media.getTitle();
final MediaDescriptionCompat.Builder builder = new MediaDescriptionCompat.Builder();
builder.setTitle(title).setDescription(Util.getMediaDescription(MediaUtils.getMediaArtist(this, media), MediaUtils.getMediaAlbum(this, media))).setIconBitmap(BitmapUtil.getPictureFromCache(media)).setMediaUri(media.getUri()).setMediaId(BrowserProvider.generateMediaId(media));
queue.add(new MediaSessionCompat.QueueItem(builder.build(), ++position));
}
mMediaSession.setQueue(queue);
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class PlaybackService method broadcastMetadata.
private void broadcastMetadata() {
final MediaWrapper media = playlistManager.getCurrentMedia();
if (media == null || isVideoPlaying())
return;
sendBroadcast(new Intent("com.android.music.metachanged").putExtra("track", media.getTitle()).putExtra("artist", media.getArtist()).putExtra("album", media.getAlbum()).putExtra("duration", media.getLength()).putExtra("playing", isPlaying()).putExtra("package", "org.videolan.vlc"));
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class PlaybackService method updateWidgetCover.
private void updateWidgetCover() {
final MediaWrapper mw = playlistManager.getCurrentMedia();
final String newWidgetCover = mw != null ? mw.getArtworkMrl() : null;
if (!TextUtils.equals(mCurrentWidgetCover, newWidgetCover)) {
mCurrentWidgetCover = newWidgetCover;
sendWidgetBroadcast(new Intent(VLCAppWidgetProvider.ACTION_WIDGET_UPDATE_COVER).putExtra("artworkMrl", newWidgetCover));
}
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class PlaybackService method showNotification.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void showNotification() {
if (!AndroidDevices.isAndroidTv && VLCApplication.showTvUi())
return;
if (isPlayingPopup() || !hasRenderer() && playlistManager.getPlayer().isVideoPlaying()) {
hideNotification();
return;
}
final MediaWrapper mw = playlistManager.getCurrentMedia();
if (mw != null) {
final boolean coverOnLockscreen = mSettings.getBoolean("lockscreen_cover", true);
final boolean playing = isPlaying();
final MediaSessionCompat.Token sessionToken = mMediaSession.getSessionToken();
final Context ctx = this;
ExecutorHolder.executorService.execute(new Runnable() {
@Override
public void run() {
if (isPlayingPopup())
return;
try {
Bitmap cover;
final String title, artist, album;
synchronized (ExecutorHolder.updateMeta) {
try {
while (ExecutorHolder.updateMeta.get()) ExecutorHolder.updateMeta.wait();
} catch (InterruptedException ignored) {
}
final MediaMetadataCompat metaData = mMediaSession != null ? mMediaSession.getController().getMetadata() : null;
title = metaData == null ? mw.getTitle() : metaData.getString(MediaMetadataCompat.METADATA_KEY_TITLE);
artist = metaData == null ? mw.getArtist() : metaData.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST);
album = metaData == null ? mw.getAlbum() : metaData.getString(MediaMetadataCompat.METADATA_KEY_ALBUM);
cover = coverOnLockscreen && metaData != null ? metaData.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART) : AudioUtil.readCoverBitmap(Uri.decode(mw.getArtworkMrl()), 256);
}
if (cover == null || cover.isRecycled())
cover = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_no_media);
final Notification notification = NotificationHelper.createPlaybackNotification(ctx, mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO), title, artist, album, cover, playing, sessionToken, getSessionPendingIntent());
if (isPlayingPopup())
return;
if (!AndroidUtil.isLolliPopOrLater || playing || mLossTransient) {
if (!mIsForeground) {
PlaybackService.this.startForeground(3, notification);
mIsForeground = true;
} else
NotificationManagerCompat.from(ctx).notify(3, notification);
} else {
if (mIsForeground) {
PlaybackService.this.stopForeground(false);
mIsForeground = false;
}
NotificationManagerCompat.from(ctx).notify(3, notification);
}
} catch (IllegalArgumentException | IllegalStateException e) {
// On somme crappy firmwares, shit can happen
Log.e(TAG, "Failed to display notification", e);
}
}
});
}
}
Aggregations