use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class PlaybackService method updateWidgetPosition.
private void updateWidgetPosition(final float pos) {
final MediaWrapper mw = playlistManager.getCurrentMedia();
if (mw == null || mWidget == 0 || isVideoPlaying())
return;
// no more than one widget mUpdateMeta for each 1/50 of the song
long timestamp = System.currentTimeMillis();
if (!playlistManager.hasCurrentMedia() || timestamp - mWidgetPositionTimestamp < mw.getLength() / 50)
return;
mWidgetPositionTimestamp = timestamp;
sendWidgetBroadcast(new Intent(VLCAppWidgetProvider.ACTION_WIDGET_UPDATE_POSITION).putExtra("position", pos));
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class PlaybackService method showWithoutParse.
/**
* Use this function to show an URI in the audio interface WITHOUT
* interrupting the stream.
*
* Mainly used by VideoPlayerActivity in response to loss of video track.
*/
@MainThread
public void showWithoutParse(int index) {
playlistManager.setVideoTrackEnabled(false);
final MediaWrapper media = playlistManager.getMedia(index);
if (media == null || !isPlaying())
return;
// Show an URI without interrupting/losing the current stream
if (BuildConfig.DEBUG)
Log.v(TAG, "Showing index " + index + " with playing URI " + media.getUri());
playlistManager.setCurrentIndex(index);
notifyTrackChanged();
showNotification();
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class PlaybackService method updateMetadata.
protected void updateMetadata() {
final MediaWrapper media = playlistManager.getCurrentMedia();
if (media == null)
return;
if (mMediaSession == null)
initMediaSession();
final Context ctx = this;
ExecutorHolder.executorService.execute(new Runnable() {
@Override
public void run() {
synchronized (ExecutorHolder.updateMeta) {
ExecutorHolder.updateMeta.set(true);
}
if (media == null)
return;
String title = media.getNowPlaying();
if (title == null)
title = media.getTitle();
boolean coverOnLockscreen = mSettings.getBoolean("lockscreen_cover", true);
final MediaMetadataCompat.Builder bob = new MediaMetadataCompat.Builder();
bob.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title).putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, BrowserProvider.generateMediaId(media)).putString(MediaMetadataCompat.METADATA_KEY_GENRE, MediaUtils.getMediaGenre(ctx, media)).putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, media.getTrackNumber()).putString(MediaMetadataCompat.METADATA_KEY_ARTIST, MediaUtils.getMediaArtist(ctx, media)).putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, MediaUtils.getMediaReferenceArtist(ctx, media)).putString(MediaMetadataCompat.METADATA_KEY_ALBUM, MediaUtils.getMediaAlbum(ctx, media)).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, getLength());
if (coverOnLockscreen) {
final Bitmap cover = AudioUtil.readCoverBitmap(Uri.decode(media.getArtworkMrl()), 512);
if (// In case of format not supported
cover != null && cover.getConfig() != null)
bob.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, cover.copy(cover.getConfig(), false));
}
bob.putLong("shuffle", 1L);
bob.putLong("repeat", getRepeatType());
VLCApplication.runOnMainThread(new Runnable() {
@Override
public void run() {
if (mMediaSession != null)
mMediaSession.setMetadata(bob.build());
synchronized (ExecutorHolder.updateMeta) {
ExecutorHolder.updateMeta.set(false);
ExecutorHolder.updateMeta.notify();
}
}
});
}
});
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class PlaybackService method updateWidgetState.
private void updateWidgetState() {
final MediaWrapper media = playlistManager.getCurrentMedia();
final Intent widgetIntent = new Intent(VLCAppWidgetProvider.ACTION_WIDGET_UPDATE);
if (playlistManager.hasCurrentMedia()) {
widgetIntent.putExtra("title", media.getTitle());
widgetIntent.putExtra("artist", media.isArtistUnknown() && media.getNowPlaying() != null ? media.getNowPlaying() : MediaUtils.getMediaArtist(PlaybackService.this, media));
} else {
widgetIntent.putExtra("title", getString(R.string.widget_default_text));
widgetIntent.putExtra("artist", "");
}
widgetIntent.putExtra("isplaying", isPlaying());
sendWidgetBroadcast(widgetIntent);
}
use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.
the class VideoGridFragment method onClick.
@Override
public void onClick(View v, int position, MediaLibraryItem item) {
final MediaWrapper media = (MediaWrapper) item;
if (mActionMode != null) {
item.toggleStateFlag(MediaLibraryItem.FLAG_SELECTED);
mAdapter.updateSelectionCount(item.hasStateFlags(MediaLibraryItem.FLAG_SELECTED));
mAdapter.notifyItemChanged(position, VideoListAdapter.UPDATE_SELECTION);
invalidateActionMode();
return;
}
final Activity activity = getActivity();
if (media instanceof MediaGroup) {
final String title = media.getTitle().substring(media.getTitle().toLowerCase().startsWith("the") ? 4 : 0);
((MainActivity) activity).showSecondaryFragment(SecondaryActivity.VIDEO_GROUP_LIST, title);
} else {
media.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
if (settings.getBoolean("force_play_all", false)) {
final List<MediaWrapper> playList = new ArrayList<>();
MediaUtils.openList(activity, playList, mAdapter.getListWithPosition(playList, position));
} else {
playVideo(media, false);
}
}
}
Aggregations