Search in sources :

Example 6 with Medialibrary

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

the class MediaWrapperList method updateWithMLMeta.

public synchronized void updateWithMLMeta() {
    final ListIterator<MediaWrapper> iter = mInternalList.listIterator();
    final Medialibrary ml = VLCApplication.getMLInstance();
    while (iter.hasNext()) {
        final MediaWrapper media = iter.next();
        if (media.getId() == 0L) {
            final MediaWrapper mw = ml.findMedia(media);
            if (mw.getId() != 0)
                iter.set(mw);
        }
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Medialibrary(org.videolan.medialibrary.Medialibrary)

Example 7 with Medialibrary

use of org.videolan.medialibrary.Medialibrary 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 8 with Medialibrary

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

the class MediaWrapperList method updateWithMLMeta.

public synchronized void updateWithMLMeta() {
    final ListIterator<MediaWrapper> iter = mInternalList.listIterator();
    final Medialibrary ml = VLCApplication.getMLInstance();
    while (iter.hasNext()) {
        final MediaWrapper media = iter.next();
        if (media.getId() == 0L) {
            final MediaWrapper mw = ml.findMedia(media);
            if (mw.getId() != 0)
                iter.set(mw);
        }
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Medialibrary(org.videolan.medialibrary.Medialibrary)

Example 9 with Medialibrary

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

the class InfoActivity method updateMeta.

private void updateMeta() {
    long length = 0L;
    MediaWrapper[] tracks = mItem.getTracks();
    int nbTracks = tracks != null ? tracks.length : 0;
    if (nbTracks > 0)
        for (MediaWrapper media : tracks) length += media.getLength();
    if (length > 0)
        mBinding.setLength(Tools.millisToText(length));
    if (mItem.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
        MediaWrapper media = (MediaWrapper) mItem;
        mBinding.setPath(Uri.decode(media.getUri().getPath()));
        mBinding.setProgress(media.getLength() == 0 ? 0 : (int) ((long) 100 * media.getTime() / length));
        mBinding.setSizeTitleText(getString(R.string.file_size));
    } else if (mItem.getItemType() == MediaLibraryItem.TYPE_ARTIST) {
        Medialibrary ml = VLCApplication.getMLInstance();
        Album[] albums = ((Artist) mItem).getAlbums();
        int nbAlbums = albums == null ? 0 : albums.length;
        mBinding.setSizeTitleText(getString(R.string.albums));
        mBinding.setSizeValueText(String.valueOf(nbAlbums));
        mBinding.setExtraTitleText(getString(R.string.tracks));
        mBinding.setExtraValueText(String.valueOf(nbTracks));
    } else {
        mBinding.setSizeTitleText(getString(R.string.tracks));
        mBinding.setSizeValueText(String.valueOf(nbTracks));
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) Medialibrary(org.videolan.medialibrary.Medialibrary)

Aggregations

Medialibrary (org.videolan.medialibrary.Medialibrary)9 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)6 PackageManager (android.content.pm.PackageManager)2 Resources (android.content.res.Resources)2 Bitmap (android.graphics.Bitmap)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 WorkerThread (android.support.annotation.WorkerThread)2 MediaBrowserCompat (android.support.v4.media.MediaBrowserCompat)2 MediaDescriptionCompat (android.support.v4.media.MediaDescriptionCompat)2 ArrayList (java.util.ArrayList)2 MediaLibraryItem (org.videolan.medialibrary.media.MediaLibraryItem)2 ExtensionListing (org.videolan.vlc.extensions.ExtensionListing)2