Search in sources :

Example 51 with MediaWrapper

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

the class BaseBrowserFragment method handleContextItemSelected.

protected boolean handleContextItemSelected(MenuItem item, final int position) {
    int id = item.getItemId();
    if (!(mAdapter.getItem(position) instanceof MediaWrapper))
        return super.onContextItemSelected(item);
    final Uri uri = ((MediaWrapper) mAdapter.getItem(position)).getUri();
    final MediaWrapper mwFromMl = "file".equals(uri.getScheme()) ? mMediaLibrary.getMedia(uri) : null;
    final MediaWrapper mw = mwFromMl != null ? mwFromMl : (MediaWrapper) mAdapter.getItem(position);
    switch(id) {
        case R.id.directory_view_play_all:
            mw.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
            playAll(mw);
            return true;
        case R.id.directory_view_append:
            {
                MediaUtils.appendMedia(getActivity(), mw);
                return true;
            }
        case R.id.directory_view_delete:
            if (checkWritePermission(mw, new Runnable() {

                @Override
                public void run() {
                    removeMedia(mw);
                }
            }))
                removeMedia(mw);
            return true;
        case R.id.directory_view_info:
            showMediaInfo(mw);
            return true;
        case R.id.directory_view_play_audio:
            mw.addFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
            MediaUtils.openMedia(getActivity(), mw);
            return true;
        case R.id.directory_view_play_folder:
            MediaUtils.openMedia(getActivity(), mw);
            return true;
        case R.id.directory_view_add_playlist:
            FragmentManager fm = getActivity().getSupportFragmentManager();
            SavePlaylistDialog savePlaylistDialog = new SavePlaylistDialog();
            Bundle infoArgs = new Bundle();
            infoArgs.putParcelableArray(SavePlaylistDialog.KEY_NEW_TRACKS, mw.getTracks());
            savePlaylistDialog.setArguments(infoArgs);
            savePlaylistDialog.show(fm, "fragment_add_to_playlist");
            return true;
        case R.id.directory_subtitles_download:
            MediaUtils.getSubs(getActivity(), mw);
            return true;
    }
    return false;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) FragmentManager(android.support.v4.app.FragmentManager) Bundle(android.os.Bundle) Uri(android.net.Uri) SavePlaylistDialog(org.videolan.vlc.gui.dialogs.SavePlaylistDialog)

Example 52 with MediaWrapper

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

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);
    WorkersKt.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);
                }
            }
            WorkersKt.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 53 with MediaWrapper

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

the class StorageBrowserFragment method onClick.

@Override
public void onClick(View v, int position, MediaLibraryItem item) {
    MediaWrapper mw = new MediaWrapper(((Storage) item).getUri());
    mw.setType(MediaWrapper.TYPE_DIR);
    browse(mw, position, ((BrowserItemBinding) DataBindingUtil.findBinding(v)).browserCheckbox.getState() == ThreeStatesCheckbox.STATE_CHECKED);
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper)

Example 54 with MediaWrapper

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

the class ExtensionManagerService method makeHostInterface.

private IExtensionHost makeHostInterface() {
    return new IExtensionHost.Stub() {

        @Override
        public void updateList(final String title, final List<VLCExtensionItem> items, final boolean showParams, final boolean isRefresh) throws RemoteException {
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    if (mExtensionManagerActivity != null)
                        mExtensionManagerActivity.displayExtensionItems(mCurrentIndex, title, items, showParams, isRefresh);
                }
            });
        }

        @Override
        public void playUri(Uri uri, String title) throws RemoteException {
            final MediaWrapper media = new MediaWrapper(uri);
            if (!TextUtils.isEmpty(title))
                ;
            media.setDisplayTitle(title);
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    MediaUtils.openMediaNoUi(ExtensionManagerService.this, media);
                }
            });
        }

        @Override
        public void unBind(int index) throws RemoteException {
            if (mCurrentIndex == index)
                mCurrentIndex = -1;
        }
    };
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) List(java.util.List) Uri(android.net.Uri)

Example 55 with MediaWrapper

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

the class Utils method mediawrapperFromExtension.

public static MediaWrapper mediawrapperFromExtension(VLCExtensionItem vlcItem) {
    MediaWrapper media = new MediaWrapper(Uri.parse(vlcItem.link));
    media.setDisplayTitle(vlcItem.title);
    if (vlcItem.type != VLCExtensionItem.TYPE_OTHER_FILE)
        media.setType(vlcItem.type);
    return media;
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper)

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