Search in sources :

Example 36 with MediaLibraryItem

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

the class MediaItemFilter method performFiltering.

@Override
protected FilterResults performFiltering(CharSequence charSequence) {
    final String[] queryStrings = charSequence.toString().trim().toLowerCase().split(" ");
    FilterResults results = new FilterResults();
    List<MediaLibraryItem> list = new ArrayList<>();
    for (MediaLibraryItem item : initData()) {
        for (String queryString : queryStrings) {
            if (queryString.length() < 2)
                continue;
            if (item.getTitle() != null && item.getTitle().toLowerCase().contains(queryString)) {
                list.add(item);
                // avoid duplicates in search results, and skip useless processing
                break;
            }
        }
    }
    results.values = list;
    results.count = list.size();
    return results;
}
Also used : MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList)

Example 37 with MediaLibraryItem

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

the class MusicFragment method onItemClicked.

@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
    MediaLibraryItem mediaLibraryItem = (MediaLibraryItem) item;
    if (mediaLibraryItem.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
        int position = 0;
        for (int i = 0; i < mDataList.length; ++i) {
            if (mediaLibraryItem.equals(mDataList[i])) {
                position = i;
                break;
            }
        }
        TvUtil.playAudioList(mContext, (MediaWrapper[]) mDataList, position);
    } else
        TvUtil.openAudioCategory(mContext, mediaLibraryItem);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem)

Example 38 with MediaLibraryItem

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

the class BrowserProvider method browse.

@WorkerThread
public static List<MediaBrowserCompat.MediaItem> browse(String parentId) {
    List<MediaBrowserCompat.MediaItem> results = new ArrayList<>();
    MediaLibraryItem[] list = null;
    boolean limitSize = false;
    Resources res = VLCApplication.getAppResources();
    // Extensions
    if (parentId.startsWith(ExtensionsManager.EXTENSION_PREFIX)) {
        if (sExtensionServiceConnection == null) {
            createExtensionServiceConnection();
            try {
                extensionLock.acquire();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if (sExtensionServiceConnection == null)
            return null;
        String[] data = parentId.split("_");
        int index = Integer.valueOf(data[1]);
        extensionItems.clear();
        if (data.length == 2) {
            // case extension root
            sExtensionManagerService.connectService(index);
        } else {
            // case sub-directory
            String stringId = parentId.replace(ExtensionsManager.EXTENSION_PREFIX + "_" + String.valueOf(index) + "_", "");
            sExtensionManagerService.browse(stringId);
        }
        try {
            extensionLock.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        results = extensionItems;
    } else {
        switch(parentId) {
            case ID_ROOT:
                MediaDescriptionCompat.Builder item = new MediaDescriptionCompat.Builder();
                // List of Extensions
                List<ExtensionListing> extensions = ExtensionsManager.getInstance().getExtensions(VLCApplication.getAppContext(), true);
                for (int i = 0; i < extensions.size(); i++) {
                    ExtensionListing extension = extensions.get(i);
                    if (extension.androidAutoEnabled() && PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).getBoolean(ExtensionsManager.EXTENSION_PREFIX + "_" + extension.componentName().getPackageName() + "_" + ExtensionsManager.ANDROID_AUTO_SUFFIX, false)) {
                        item.setMediaId(ExtensionsManager.EXTENSION_PREFIX + "_" + String.valueOf(i)).setTitle(extension.title());
                        int iconRes = extension.menuIcon();
                        Bitmap b = null;
                        Resources extensionRes;
                        if (iconRes != 0) {
                            try {
                                extensionRes = VLCApplication.getAppContext().getPackageManager().getResourcesForApplication(extension.componentName().getPackageName());
                                b = BitmapFactory.decodeResource(extensionRes, iconRes);
                            } catch (PackageManager.NameNotFoundException e) {
                            }
                        }
                        if (b != null)
                            item.setIconBitmap(b);
                        else
                            try {
                                b = ((BitmapDrawable) VLCApplication.getAppContext().getPackageManager().getApplicationIcon(extension.componentName().getPackageName())).getBitmap();
                                item.setIconBitmap(b);
                            } catch (PackageManager.NameNotFoundException e) {
                                b = BitmapFactory.decodeResource(res, R.drawable.icon);
                                item.setIconBitmap(b);
                            }
                        results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
                    }
                }
                // Last added
                item = new MediaDescriptionCompat.Builder().setMediaId(ID_LAST_ADDED).setTitle(res.getString(R.string.last_added_media)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_history_normal"));
                results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
                // History
                item = new MediaDescriptionCompat.Builder().setMediaId(ID_HISTORY).setTitle(res.getString(R.string.history)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_history_normal"));
                results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
                // Playlists
                item.setMediaId(ID_PLAYLISTS).setTitle(res.getString(R.string.playlists)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_playlist_normal"));
                results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
                // Artists
                item.setMediaId(ID_ARTISTS).setTitle(res.getString(R.string.artists)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_artist_normal"));
                results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
                // Albums
                item.setMediaId(ID_ALBUMS).setTitle(res.getString(R.string.albums)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_album_normal"));
                results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
                // Songs
                item.setMediaId(ID_SONGS).setTitle(res.getString(R.string.songs)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_audio_normal"));
                results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
                // Genres
                item.setMediaId(ID_GENRES).setTitle(res.getString(R.string.genres)).setIconUri(Uri.parse(BASE_DRAWABLE_URI + "ic_auto_genre_normal"));
                results.add(new MediaBrowserCompat.MediaItem(item.build(), MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
                return results;
            case ID_LAST_ADDED:
                limitSize = true;
                list = VLCApplication.getMLInstance().getRecentAudio();
                break;
            case ID_HISTORY:
                limitSize = true;
                list = VLCApplication.getMLInstance().lastMediaPlayed();
                break;
            case ID_ARTISTS:
                list = VLCApplication.getMLInstance().getArtists(VLCApplication.getSettings().getBoolean(Constants.KEY_ARTISTS_SHOW_ALL, false));
                break;
            case ID_ALBUMS:
                list = VLCApplication.getMLInstance().getAlbums();
                break;
            case ID_GENRES:
                list = VLCApplication.getMLInstance().getGenres();
                break;
            case ID_PLAYLISTS:
                list = VLCApplication.getMLInstance().getPlaylists();
                break;
            case ID_SONGS:
                list = VLCApplication.getMLInstance().getAudio();
                break;
            default:
                String[] idSections = parentId.split("_");
                Medialibrary ml = VLCApplication.getMLInstance();
                long id = Long.parseLong(idSections[1]);
                switch(idSections[0]) {
                    case ARTIST_PREFIX:
                        list = ml.getArtist(id).getAlbums();
                        break;
                    case GENRE_PREFIX:
                        list = ml.getGenre(id).getAlbums();
                        break;
                }
        }
        if (list != null) {
            MediaDescriptionCompat.Builder item = new MediaDescriptionCompat.Builder();
            for (MediaLibraryItem libraryItem : list) {
                if (libraryItem == null || (libraryItem.getItemType() == MediaLibraryItem.TYPE_MEDIA && ((MediaWrapper) libraryItem).getType() != MediaWrapper.TYPE_AUDIO))
                    continue;
                Bitmap cover = AudioUtil.readCoverBitmap(Uri.decode(libraryItem.getArtworkMrl()), 256);
                if (cover == null)
                    cover = DEFAULT_AUDIO_COVER;
                item.setTitle(libraryItem.getTitle()).setMediaId(generateMediaId(libraryItem));
                item.setIconBitmap(cover);
                if (libraryItem.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
                    item.setMediaUri(((MediaWrapper) libraryItem).getUri()).setSubtitle(MediaUtils.getMediaSubtitle((MediaWrapper) libraryItem));
                } else
                    item.setSubtitle(libraryItem.getDescription());
                boolean playable = libraryItem.getItemType() == MediaLibraryItem.TYPE_MEDIA || libraryItem.getItemType() == MediaLibraryItem.TYPE_ALBUM || libraryItem.getItemType() == MediaLibraryItem.TYPE_PLAYLIST;
                results.add(new MediaBrowserCompat.MediaItem(item.build(), playable ? MediaBrowserCompat.MediaItem.FLAG_PLAYABLE : MediaBrowserCompat.MediaItem.FLAG_BROWSABLE));
                if (limitSize && results.size() == MAX_HISTORY_SIZE)
                    break;
            }
        }
    }
    if (results.isEmpty()) {
        MediaDescriptionCompat.Builder mediaItem = new MediaDescriptionCompat.Builder();
        mediaItem.setMediaId(DUMMY);
        mediaItem.setTitle(VLCApplication.getAppContext().getString(R.string.search_no_result));
        results.add(new MediaBrowserCompat.MediaItem(mediaItem.build(), 0));
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) Bitmap(android.graphics.Bitmap) Medialibrary(org.videolan.medialibrary.Medialibrary) PackageManager(android.content.pm.PackageManager) MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ExtensionListing(org.videolan.vlc.extensions.ExtensionListing) MediaBrowserCompat(android.support.v4.media.MediaBrowserCompat) Resources(android.content.res.Resources) MediaDescriptionCompat(android.support.v4.media.MediaDescriptionCompat) WorkerThread(android.support.annotation.WorkerThread)

Example 39 with MediaLibraryItem

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

the class CardPresenter method onBindViewHolder.

@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, final Object item) {
    final ViewHolder holder = ((ViewHolder) viewHolder);
    if (item instanceof MediaWrapper) {
        final MediaWrapper mw = (MediaWrapper) item;
        holder.mCardView.setTitleText(mw.getTitle());
        holder.mCardView.setContentText(mw.getDescription());
        holder.updateCardViewImage(mw);
        if (mIsSeenMediaMarkerVisible && mw.getType() == MediaWrapper.TYPE_VIDEO && mw.getSeen() > 0L)
            holder.mCardView.setBadgeImage(ContextCompat.getDrawable(mContext, R.drawable.ic_seen_tv_normal));
        holder.view.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                TvUtil.INSTANCE.showMediaDetail(v.getContext(), mw);
                return true;
            }
        });
    } else if (item instanceof MediaLibraryItem) {
        final MediaLibraryItem mediaLibraryItem = (MediaLibraryItem) item;
        holder.mCardView.setTitleText(mediaLibraryItem.getTitle());
        holder.mCardView.setContentText(mediaLibraryItem.getDescription());
        holder.updateCardViewImage(mediaLibraryItem);
    } else if (item instanceof SimpleCard) {
        SimpleCard card = (SimpleCard) item;
        Bitmap image = card.getImage();
        holder.mCardView.setTitleText(card.getName());
        holder.mCardView.setContentText(card.getDescription());
        holder.updateCardViewImage(image != null ? new BitmapDrawable(mRes, image) : ContextCompat.getDrawable(mContext, card.getImageId()));
    } else if (item instanceof String) {
        holder.mCardView.setTitleText((String) item);
        holder.mCardView.setContentText("");
        holder.updateCardViewImage(sDefaultCardImage);
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Bitmap(android.graphics.Bitmap) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageCardView(android.support.v17.leanback.widget.ImageCardView) ImageView(android.widget.ImageView) View(android.view.View)

Example 40 with MediaLibraryItem

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

the class AudioAlbumsSongsFragment method onFabPlayClick.

@Override
@SuppressWarnings("unchecked")
public void onFabPlayClick(View view) {
    final List<MediaWrapper> list;
    if (mViewPager.getCurrentItem() == 0) {
        list = new ArrayList<>();
        for (MediaLibraryItem item : mAlbumsAdapter.getMediaItems()) list.addAll(Util.arrayToArrayList(item.getTracks()));
    } else {
        list = (List<MediaWrapper>) (List<?>) mSongsAdapter.getMediaItems();
    }
    MediaUtils.openList(getActivity(), list, 0);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

MediaLibraryItem (org.videolan.medialibrary.media.MediaLibraryItem)46 ArrayList (java.util.ArrayList)25 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)23 Bitmap (android.graphics.Bitmap)8 BitmapDrawable (android.graphics.drawable.BitmapDrawable)8 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)8 List (java.util.List)7 View (android.view.View)6 RecyclerView (android.support.v7.widget.RecyclerView)5 TextView (android.widget.TextView)4 Playlist (org.videolan.medialibrary.media.Playlist)4 Bundle (android.os.Bundle)3 LinkedList (java.util.LinkedList)3 Storage (org.videolan.medialibrary.media.Storage)3 ContextMenuRecyclerView (org.videolan.vlc.gui.view.ContextMenuRecyclerView)3 PackageManager (android.content.pm.PackageManager)2 Resources (android.content.res.Resources)2 WorkerThread (android.support.annotation.WorkerThread)2 TextInputLayout (android.support.design.widget.TextInputLayout)2 ImageCardView (android.support.v17.leanback.widget.ImageCardView)2