Search in sources :

Example 1 with MediaWrapper

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));
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 2 with MediaWrapper

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();
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MainThread(android.support.annotation.MainThread)

Example 3 with MediaWrapper

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();
                    }
                }
            });
        }
    });
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Context(android.content.Context) MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) Bitmap(android.graphics.Bitmap)

Example 4 with MediaWrapper

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);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 5 with MediaWrapper

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);
        }
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaGroup(org.videolan.vlc.media.MediaGroup) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) SecondaryActivity(org.videolan.vlc.gui.SecondaryActivity) MainActivity(org.videolan.vlc.gui.MainActivity) Activity(android.app.Activity) MainActivity(org.videolan.vlc.gui.MainActivity)

Aggregations

MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)157 ArrayList (java.util.ArrayList)36 MediaLibraryItem (org.videolan.medialibrary.media.MediaLibraryItem)23 Bitmap (android.graphics.Bitmap)18 Intent (android.content.Intent)16 Uri (android.net.Uri)15 List (java.util.List)11 Bundle (android.os.Bundle)10 Context (android.content.Context)9 MediaGroup (org.videolan.vlc.media.MediaGroup)9 PendingIntent (android.app.PendingIntent)8 View (android.view.View)8 TargetApi (android.annotation.TargetApi)6 Cursor (android.database.Cursor)6 FragmentManager (android.support.v4.app.FragmentManager)6 File (java.io.File)6 LinkedList (java.util.LinkedList)6 Medialibrary (org.videolan.medialibrary.Medialibrary)6 SavePlaylistDialog (org.videolan.vlc.gui.dialogs.SavePlaylistDialog)6 SharedPreferences (android.content.SharedPreferences)5