Search in sources :

Example 21 with MediaWrapper

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

the class BaseBrowserFragment method onMediaAdded.

@Override
public void onMediaAdded(final int index, final Media media) {
    if (refreshing && !mRoot) {
        MediaWrapper mediaWrapper = getMediaWrapper(new MediaWrapper(media));
        refreshList.add(mediaWrapper);
        return;
    }
    final MediaWrapper mediaWrapper = getMediaWrapper(new MediaWrapper(media));
    VLCApplication.runOnMainThread(new Runnable() {

        @Override
        public void run() {
            mAdapter.addItem(mediaWrapper, false);
        }
    });
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper)

Example 22 with MediaWrapper

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

the class FileBrowserFragment method browseRoot.

@Override
protected void browseRoot() {
    mMrl = null;
    mRoot = true;
    final FragmentActivity activity = getActivity();
    if (activity == null)
        return;
    activity.setTitle(R.string.directories);
    final String internalmemoryTitle = getString(R.string.internal_memory);
    final String browserStorage = getString(R.string.browser_storages);
    final String quickAccess = getString(R.string.browser_quick_access);
    VLCApplication.runBackground(new Runnable() {

        @Override
        public void run() {
            final String[] storages = AndroidDevices.getMediaDirectories();
            MediaWrapper directory;
            final ArrayList<MediaLibraryItem> devices = new ArrayList<>(storages.length);
            final boolean isFilePicker = FileBrowserFragment.this instanceof FilePickerFragment;
            if (!isFilePicker) {
                devices.add(new DummyItem(browserStorage));
            }
            for (String mediaDirLocation : storages) {
                if (!(new File(mediaDirLocation).exists()))
                    continue;
                directory = new MediaWrapper(AndroidUtil.PathToUri(mediaDirLocation));
                directory.setType(MediaWrapper.TYPE_DIR);
                if (TextUtils.equals(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY, mediaDirLocation))
                    directory.setDisplayTitle(internalmemoryTitle);
                else {
                    final String deviceName = FileUtils.getStorageTag(directory.getTitle());
                    if (deviceName != null)
                        directory.setDisplayTitle(deviceName);
                }
                devices.add(directory);
            }
            // Set folders shortcuts
            if (!isFilePicker) {
                devices.add(new DummyItem(quickAccess));
            }
            if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_FILE.exists()) {
                final MediaWrapper movies = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MOVIES_DIRECTORY_URI);
                movies.setType(MediaWrapper.TYPE_DIR);
                devices.add(movies);
            }
            if (!isFilePicker) {
                if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_FILE.exists()) {
                    final MediaWrapper music = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_MUSIC_DIRECTORY_URI);
                    music.setType(MediaWrapper.TYPE_DIR);
                    devices.add(music);
                }
                if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_PODCAST_DIRECTORY_FILE.exists()) {
                    final MediaWrapper podcasts = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_PODCAST_DIRECTORY_URI);
                    podcasts.setType(MediaWrapper.TYPE_DIR);
                    devices.add(podcasts);
                }
                if (AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_DOWNLOAD_DIRECTORY_FILE.exists()) {
                    final MediaWrapper downloads = new MediaWrapper(AndroidDevices.MediaFolders.EXTERNAL_PUBLIC_DOWNLOAD_DIRECTORY_URI);
                    downloads.setType(MediaWrapper.TYPE_DIR);
                    devices.add(downloads);
                }
                if (AndroidDevices.MediaFolders.WHATSAPP_VIDEOS_FILE.exists()) {
                    final MediaWrapper whatsapp = new MediaWrapper(AndroidDevices.MediaFolders.WHATSAPP_VIDEOS_FILE_URI);
                    whatsapp.setType(MediaWrapper.TYPE_DIR);
                    devices.add(whatsapp);
                }
            }
            VLCApplication.runOnMainThread(new Runnable() {

                @Override
                public void run() {
                    mAdapter.update(devices);
                }
            });
        }
    });
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) FragmentActivity(android.support.v4.app.FragmentActivity) DummyItem(org.videolan.medialibrary.media.DummyItem) ArrayList(java.util.ArrayList) File(java.io.File)

Example 23 with MediaWrapper

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

the class FilePickerAdapter method onBindViewHolder.

public void onBindViewHolder(final ViewHolder holder, int position) {
    if (holder instanceof MediaViewHolder) {
        final MediaViewHolder vh = (MediaViewHolder) holder;
        final MediaWrapper media = (MediaWrapper) getItem(position);
        vh.binding.setItem(media);
        vh.binding.setHasContextMenu(false);
        vh.binding.setProtocol(null);
        vh.binding.setCover(getIcon(media, false));
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper)

Example 24 with MediaWrapper

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

the class NetworkBrowserFragment method updateFavorites.

private void updateFavorites() {
    updateEmptyView();
    if (!ExternalMonitor.isConnected()) {
        if (mFavorites != 0) {
            mAdapter.clear();
            mFavorites = 0;
        }
        return;
    }
    List<MediaWrapper> favs = MediaDatabase.getInstance().getAllNetworkFav();
    int newSize = favs.size();
    if (newSize == 0 && mFavorites == 0)
        return;
    if (!allowLAN()) {
        List<MediaWrapper> toRemove = new ArrayList<>();
        List<String> schemes = Arrays.asList("ftp", "sftp", "ftps", "http", "https");
        for (MediaWrapper mw : favs) if (!schemes.contains(mw.getUri().getScheme()))
            toRemove.add(mw);
        if (!toRemove.isEmpty())
            for (MediaWrapper mw : toRemove) favs.remove(mw);
        newSize = favs.size();
        if (newSize == 0) {
            if (mFavorites != 0) {
                mAdapter.clear();
                mFavorites = 0;
            }
            return;
        }
    }
    if (mFavorites != 0 && !mAdapter.getAll().isEmpty())
        for (int i = 1; i <= mFavorites; ++i) {
            // remove former favorites
            mAdapter.removeItem(1);
        }
    if (newSize == 0 && !mAdapter.isEmpty()) {
        // also remove separator if no more fav
        mAdapter.removeItem(0);
        // also remove separator if no more fav
        mAdapter.removeItem(0);
    } else {
        boolean isEmpty = mAdapter.isEmpty();
        if (mFavorites == 0 || isEmpty)
            // add header if needed
            mAdapter.addItem(new DummyItem(getString(R.string.network_favorites)), false, 0);
        for (int i = 0; i < newSize; ) {
            // add new favorites
            mAdapter.addItem(favs.get(i), false, ++i);
        }
        if (mFavorites == 0 || isEmpty)
            // add header if needed
            mAdapter.addItem(new DummyItem(getString(R.string.network_shared_folders)), false, newSize + 1);
    }
    // update count
    mFavorites = newSize;
    if (newSize != 0)
        mHandler.sendEmptyMessage(BrowserFragmentHandler.MSG_HIDE_LOADING);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) DummyItem(org.videolan.medialibrary.media.DummyItem) ArrayList(java.util.ArrayList)

Example 25 with MediaWrapper

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

the class AudioAlbumsSongsFragment method handleContextItemSelected.

protected boolean handleContextItemSelected(MenuItem item, final int position) {
    int startPosition;
    MediaWrapper[] medias;
    int id = item.getItemId();
    final AudioBrowserAdapter adapter = mViewPager.getCurrentItem() == MODE_ALBUM ? mAlbumsAdapter : mSongsAdapter;
    final MediaLibraryItem mediaItem = adapter.getItem(position);
    boolean useAllItems = id == R.id.audio_list_browser_play_all;
    boolean append = id == R.id.audio_list_browser_append;
    boolean insert_next = id == R.id.audio_list_browser_insert_next;
    if (id == R.id.audio_list_browser_delete) {
        adapter.remove(mediaItem);
        final Runnable cancel = new Runnable() {

            @Override
            public void run() {
                adapter.addItems(mediaItem);
            }
        };
        UiTools.snackerWithCancel(mViewPager, getString(R.string.file_deleted), new Runnable() {

            @Override
            public void run() {
                deleteMedia(mediaItem, true, cancel);
            }
        }, cancel);
        return true;
    }
    if (id == R.id.audio_list_browser_set_song) {
        AudioUtil.setRingtone((MediaWrapper) mediaItem, getActivity());
        return true;
    }
    if (id == R.id.audio_view_info) {
        showInfoDialog((MediaWrapper) mediaItem);
        return true;
    }
    if (id == R.id.audio_view_add_playlist) {
        FragmentManager fm = getActivity().getSupportFragmentManager();
        SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
        Bundle args = new Bundle();
        args.putParcelableArray(SavePlaylistDialog.KEY_NEW_TRACKS, mediaItem.getTracks());
        savePlaylistDialog.setArguments(args);
        savePlaylistDialog.show(fm, "fragment_add_to_playlist");
        return true;
    }
    if (useAllItems) {
        List<MediaLibraryItem> items = new ArrayList<>();
        startPosition = mSongsAdapter.getListWithPosition(items, position);
        medias = items.toArray(new MediaWrapper[items.size()]);
    } else {
        startPosition = 0;
        if (mediaItem instanceof Album)
            medias = mediaItem.getTracks();
        else
            medias = new MediaWrapper[] { (MediaWrapper) mediaItem };
    }
    if (mService != null) {
        if (append)
            mService.append(medias);
        else if (insert_next)
            mService.insertNext(medias);
        else
            mService.load(medias, startPosition);
        return true;
    }
    return false;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) MediaLibraryItem(org.videolan.medialibrary.media.MediaLibraryItem) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Album(org.videolan.medialibrary.media.Album) SavePlaylistDialog(org.videolan.vlc.gui.dialogs.SavePlaylistDialog) FragmentManager(android.support.v4.app.FragmentManager)

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