Search in sources :

Example 81 with MediaWrapper

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;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) FragmentManager(android.support.v4.app.FragmentManager) Bundle(android.os.Bundle) SavePlaylistDialog(org.videolan.vlc.gui.dialogs.SavePlaylistDialog)

Example 82 with MediaWrapper

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);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat) LinkedList(java.util.LinkedList) MediaDescriptionCompat(android.support.v4.media.MediaDescriptionCompat)

Example 83 with MediaWrapper

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

Example 84 with MediaWrapper

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

Example 85 with MediaWrapper

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

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