Search in sources :

Example 1 with MediaLibraryItem

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

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 2 with MediaLibraryItem

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

the class MediaItemDiffCallback method areItemsTheSame.

@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
    final MediaLibraryItem oldItem = oldList.get(oldItemPosition);
    final MediaLibraryItem newItem = newList.get(newItemPosition);
    return oldItem == newItem || ((oldItem == null) == (newItem == null) && oldItem.equals(newItem));
}
Also used : MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem)

Example 3 with MediaLibraryItem

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

the class PlaylistActivity method onActionItemClicked.

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    List<MediaLibraryItem> list = mAdapter.getSelection();
    List<MediaWrapper> tracks = new ArrayList<>();
    for (MediaLibraryItem mediaItem : list) tracks.addAll(Arrays.asList(mediaItem.getTracks()));
    if (item.getItemId() == R.id.action_mode_audio_playlist_up) {
        Toast.makeText(this, "UP !", Toast.LENGTH_SHORT).show();
        return true;
    }
    if (item.getItemId() == R.id.action_mode_audio_playlist_down) {
        Toast.makeText(this, "DOWN !", Toast.LENGTH_SHORT).show();
        return true;
    }
    stopActionMode();
    switch(item.getItemId()) {
        case R.id.action_mode_audio_play:
            mService.load(tracks, 0);
            break;
        case R.id.action_mode_audio_append:
            mService.append(tracks);
            break;
        case R.id.action_mode_audio_add_playlist:
            ;
            UiTools.addToPlaylist(this, tracks);
            break;
        case R.id.action_mode_audio_info:
            showInfoDialog((MediaWrapper) list.get(0));
            break;
        case R.id.action_mode_audio_set_song:
            AudioUtil.setRingtone((MediaWrapper) list.get(0), this);
            break;
        case R.id.action_mode_audio_delete:
            removeFromPlaylist(tracks);
            break;
        default:
            return false;
    }
    return true;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) ArrayList(java.util.ArrayList)

Example 4 with MediaLibraryItem

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

the class StorageBrowserAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final MediaViewHolder vh = (MediaViewHolder) holder;
    MediaLibraryItem storage = getItem(position);
    if (storage.getItemType() == MediaLibraryItem.TYPE_MEDIA)
        storage = new Storage(((MediaWrapper) storage).getUri());
    String storagePath = ((Storage) storage).getUri().getPath();
    if (!storagePath.endsWith("/"))
        storagePath += "/";
    boolean hasContextMenu = mCustomDirsLocation.contains(storagePath);
    boolean checked = ((StorageBrowserFragment) fragment).mScannedDirectory || mMediaDirsLocation.contains(storagePath);
    vh.binding.setItem(storage);
    vh.binding.setHasContextMenu(hasContextMenu);
    if (checked)
        vh.binding.browserCheckbox.setState(ThreeStatesCheckbox.STATE_CHECKED);
    else if (hasDiscoveredChildren(storagePath))
        vh.binding.browserCheckbox.setState(ThreeStatesCheckbox.STATE_PARTIAL);
    else
        vh.binding.browserCheckbox.setState(ThreeStatesCheckbox.STATE_UNCHECKED);
    vh.binding.setCheckEnabled(!((StorageBrowserFragment) fragment).mScannedDirectory);
}
Also used : Storage(org.videolan.medialibrary.media.Storage) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem)

Example 5 with MediaLibraryItem

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

the class BaseBrowserFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (mAdapter == null)
        mAdapter = new BaseBrowserAdapter(this);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mAdapter);
    registerForContextMenu(mRecyclerView);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    @SuppressWarnings("unchecked") final SimpleArrayMap<MediaLibraryItem, List<MediaLibraryItem>> content = (SimpleArrayMap<MediaLibraryItem, List<MediaLibraryItem>>) VLCApplication.getData(KEY_CONTENT_LIST + mMrl);
    if (content != null)
        mFoldersContentLists = content;
    @SuppressWarnings("unchecked") final List<MediaLibraryItem> mediaList = mRoot ? null : (List<MediaLibraryItem>) VLCApplication.getData(KEY_MEDIA_LIST + mMrl);
    if (!Util.isListEmpty(mediaList)) {
        mAdapter.update(mediaList);
        parseSubDirectories();
    } else
        mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_REFRESH);
}
Also used : MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) SimpleArrayMap(android.support.v4.util.SimpleArrayMap) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

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