Search in sources :

Example 71 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by GeoffreyMetais.

the class UiTools method setOnDragListener.

public static void setOnDragListener(final Activity activity) {
    final View view = AndroidUtil.isNougatOrLater ? activity.getWindow().peekDecorView() : null;
    if (view != null)
        view.setOnDragListener(new View.OnDragListener() {

            @Override
            public boolean onDrag(View v, DragEvent event) {
                switch(event.getAction()) {
                    case DragEvent.ACTION_DRAG_STARTED:
                        return true;
                    case DragEvent.ACTION_DROP:
                        final ClipData clipData = event.getClipData();
                        if (clipData == null)
                            return false;
                        final int itemsCount = clipData.getItemCount();
                        for (int i = 0; i < itemsCount; i++) {
                            final DragAndDropPermissions permissions = activity.requestDragAndDropPermissions(event);
                            if (permissions != null) {
                                final ClipData.Item item = clipData.getItemAt(i);
                                if (item.getUri() != null)
                                    MediaUtils.openUri(activity, item.getUri());
                                else if (item.getText() != null) {
                                    final Uri uri = Uri.parse(item.getText().toString());
                                    final MediaWrapper media = new MediaWrapper(uri);
                                    if (!"file".equals(uri.getScheme()))
                                        media.setType(MediaWrapper.TYPE_STREAM);
                                    MediaUtils.openMedia(activity, media);
                                }
                                return true;
                            }
                        }
                        return false;
                    default:
                        return false;
                }
            }
        });
}
Also used : DragEvent(android.view.DragEvent) MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) DragAndDropPermissions(android.view.DragAndDropPermissions) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ClipData(android.content.ClipData) Uri(android.net.Uri)

Example 72 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by GeoffreyMetais.

the class VideoListAdapter method getListWithPosition.

int getListWithPosition(List<MediaWrapper> list, int position) {
    MediaWrapper mw;
    int offset = 0;
    for (int i = 0; i < getItemCount(); ++i) {
        mw = getDataset().get(i);
        if (mw instanceof MediaGroup) {
            for (MediaWrapper item : ((MediaGroup) mw).getAll()) list.add(item);
            if (i < position)
                offset += ((MediaGroup) mw).size() - 1;
        } else
            list.add(mw);
    }
    return position + offset;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaGroup(org.videolan.vlc.media.MediaGroup)

Example 73 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by GeoffreyMetais.

the class AsyncImageLoader method loadPicture.

@BindingAdapter({ "media" })
public static void loadPicture(View v, MediaLibraryItem item) {
    if (item == null || item.getItemType() == MediaLibraryItem.TYPE_GENRE || item.getItemType() == MediaLibraryItem.TYPE_PLAYLIST)
        return;
    final boolean isMedia = item.getItemType() == MediaLibraryItem.TYPE_MEDIA;
    final boolean isGroup = isMedia && ((MediaWrapper) item).getType() == MediaWrapper.TYPE_GROUP;
    final String cacheKey = isGroup ? "group:" + item.getTitle() : ThumbnailsProvider.getMediaCacheKey(isMedia, item);
    final Bitmap bitmap = cacheKey != null ? sBitmapCache.getBitmapFromMemCache(cacheKey) : null;
    if (bitmap != null) {
        updateTargetImage(bitmap, v, DataBindingUtil.findBinding(v));
        return;
    }
    if (isMedia && !isGroup && item.getId() == 0L) {
        MediaWrapper mw = (MediaWrapper) item;
        final int type = mw.getType();
        final boolean isMediaFile = type == MediaWrapper.TYPE_AUDIO || type == MediaWrapper.TYPE_VIDEO;
        final Uri uri = mw.getUri();
        if (!isMediaFile && !(type == MediaWrapper.TYPE_DIR && "upnp".equals(uri.getScheme())))
            return;
        if (isMediaFile && "file".equals(uri.getScheme())) {
            mw = sMedialibrary.getMedia(uri);
            if (mw != null)
                item = mw;
        }
    }
    loadImage(MLItemCoverFetcher.obtain().init(v, item), v);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Bitmap(android.graphics.Bitmap) Uri(android.net.Uri) BindingAdapter(android.databinding.BindingAdapter)

Example 74 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by GeoffreyMetais.

the class CardPresenter method onBindViewHolder.

@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item, List<Object> payloads) {
    if (payloads.isEmpty())
        onBindViewHolder(viewHolder, item);
    else {
        final ViewHolder holder = ((ViewHolder) viewHolder);
        final MediaLibraryItem media = (MediaLibraryItem) item;
        for (Object data : payloads) {
            switch((int) data) {
                case Constants.UPDATE_DESCRIPTION:
                    holder.mCardView.setContentText(media.getDescription());
                    break;
                case Constants.UPDATE_THUMB:
                    AsyncImageLoader.loadPicture(holder.mCardView, media);
                    break;
                case Constants.UPDATE_TIME:
                    final MediaWrapper mediaWrapper = (MediaWrapper) item;
                    Tools.setMediaDescription(mediaWrapper);
                    holder.mCardView.setContentText(mediaWrapper.getDescription());
                    // update seen check if time is reset to 0
                    if (mediaWrapper.getTime() > 0)
                        break;
                case Constants.UPDATE_SEEN:
                    final MediaWrapper mw = (MediaWrapper) item;
                    if (mIsSeenMediaMarkerVisible && mw.getType() == MediaWrapper.TYPE_VIDEO && mw.getSeen() > 0L)
                        holder.mCardView.setBadgeImage(ContextCompat.getDrawable(mContext, R.drawable.ic_seen_tv_normal));
                    break;
            }
        }
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem)

Example 75 with MediaWrapper

use of org.videolan.medialibrary.media.MediaWrapper in project vlc-android by videolan.

the class Medialibrary method findMedia.

// If media is not in ML, find it with its path
public MediaWrapper findMedia(MediaWrapper mw) {
    if (mIsInitiated && mw != null && mw.getId() == 0L) {
        Uri uri = mw.getUri();
        MediaWrapper libraryMedia = getMedia(uri);
        if (libraryMedia == null && TextUtils.equals("file", uri.getScheme()) && uri.getPath() != null && uri.getPath().startsWith("/sdcard")) {
            uri = Tools.convertLocalUri(uri);
            libraryMedia = getMedia(uri);
        }
        if (libraryMedia != null)
            return libraryMedia;
    }
    return mw;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Uri(android.net.Uri)

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