public void sortByAlbum() { mItems.clear(); for (ListItem album : mSeparatorItemMap.values()) { mItems.add(album); Collections.sort(album.mMediaList, MediaComparators.byTrackNumber); for (Media media : album.mMediaList) add(media.getTitle(), null, media); } }
public static void setPicture(Context context, Media m, Bitmap p) { Log.d(TAG, "Setting new picture for " + m.getTitle()); try { MediaDatabase.getInstance(context) .updateMedia(m.getLocation(), MediaDatabase.mediaColumn.MEDIA_PICTURE, p); } catch (SQLiteFullException e) { Log.d(TAG, "SQLiteFullException while setting picture"); } m.setPictureParsed(true); }
/** * Returns a single list containing all media, along with the position of the first media in * 'position' in the _new_ single list. * * @param outputList The list to be written to. * @param position Position to retrieve in to _this_ adapter. * @return The position of 'position' in the new single list, or 0 if not found. */ public int getListWithPosition(List<String> outputList, int position) { int outputPosition = 0; outputList.clear(); for (int i = 0; i < mItems.size(); i++) { if (!mItems.get(i).mIsSeparator) { if (position == i && !mItems.get(i).mMediaList.isEmpty()) outputPosition = outputList.size(); for (Media k : mItems.get(i).mMediaList) { outputList.add(k.getLocation()); } } } return outputPosition; }
private void setContextMenuItems(Menu menu, MediaWrapper mediaWrapper) { long lastTime = mediaWrapper.getTime(); if (lastTime > 0) menu.findItem(R.id.video_list_play_from_start).setVisible(true); boolean hasInfo = false; final Media media = new Media(VLCInstance.get(), mediaWrapper.getUri()); media.parse(); media.release(); if (media.getMeta(Media.Meta.Title) != null) hasInfo = true; menu.findItem(R.id.video_list_info).setVisible(hasInfo); menu.findItem(R.id.video_list_delete) .setVisible( !AndroidUtil.isLolliPopOrLater() || mediaWrapper .getLocation() .startsWith("file://" + AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)); }
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; View view = convertView; if (view == null) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false); holder = new ViewHolder(); holder.text = (TextView) view.findViewById(android.R.id.text1); view.setTag(holder); } else holder = (ViewHolder) view.getTag(); Media item = getItem(position); holder.text.setText(item.getTitle()); return view; }
private void init(Media media) { mType = TYPE_ALL; if (media != null) { if (media.isParsed()) { mLength = media.getDuration(); for (int i = 0; i < media.getTrackCount(); ++i) { final Media.Track track = media.getTrack(i); if (track == null) continue; if (track.type == Media.Track.Type.Video) { final Media.VideoTrack videoTrack = (VideoTrack) track; mType = TYPE_VIDEO; mWidth = videoTrack.width; mHeight = videoTrack.height; } else if (mType == TYPE_ALL && track.type == Media.Track.Type.Audio) { mType = TYPE_AUDIO; } } } updateMeta(media); if (mType == TYPE_ALL && media.getType() == Media.Type.Directory) mType = TYPE_DIR; } if (mType == TYPE_ALL) { final String location = mUri.toString(); int dotIndex = location.lastIndexOf("."); if (dotIndex != -1) { String fileExt = location.substring(dotIndex).toLowerCase(Locale.ENGLISH); if (Extensions.VIDEO.contains(fileExt)) { mType = TYPE_VIDEO; } else if (Extensions.AUDIO.contains(fileExt)) { mType = TYPE_AUDIO; } else if (Extensions.SUBTITLES.contains(fileExt)) { mType = TYPE_SUBTITLE; } else if (Extensions.PLAYLIST.contains(fileExt)) { mType = TYPE_PLAYLIST; } } } }
public static Bitmap getPictureFromCache(Media media) { // mPicture is not null only if passed through // the ctor which is deprecated by now. Bitmap b = media.getPicture(); if (b == null) { BitmapCache cache = BitmapCache.getInstance(); Bitmap picture = cache.getBitmapFromMemCache(media.getLocation()); if (picture == null) { /* Not in memcache: * serving the file from the database and * adding it to the memcache for later use. */ Context c = VLCApplication.getAppContext(); picture = MediaDatabase.getInstance(c).getPicture(c, media.getLocation()); cache.addBitmapToMemCache(media.getLocation(), picture); } return picture; } else { return b; } }
public void setVideoPath(String path) { mCurrentVideoPath = path; if (nativeMode) { try { mVideoView.setVideoPath(path); } catch (IllegalStateException e) { TvApp.getApplication() .getLogger() .ErrorException("Unable to set video path. Probably backing out.", e); } } else { mSurfaceHolder.setKeepScreenOn(true); mCurrentMedia = new Media(mLibVLC, Uri.parse(path)); mCurrentMedia.parse(); mVlcPlayer.setMedia(mCurrentMedia); mCurrentMedia.release(); } }
/** * Remove all the reference to a media in the list items. Remove also all the list items that * contain only this media. * * @param media the media to remove */ public void removeMedia(Media media) { for (int i = 0; i < mItems.size(); ++i) { ListItem item = mItems.get(i); if (item.mMediaList == null) continue; for (int j = 0; j < item.mMediaList.size(); ++j) if (item.mMediaList.get(j).getLocation().equals(media.getLocation())) { item.mMediaList.remove(j); j--; } if (item.mMediaList.isEmpty() && !item.mIsSeparator) { mItems.remove(i); i--; } } notifyDataSetChanged(); }
private void updateList() { if (mediaList == null) return; mAlbumsAdapter.clear(); mSongsAdapter.clear(); Collections.sort(mediaList, MediaComparators.byAlbum); String lastAlbumName = new String(); for (int i = 0; i < mediaList.size(); ++i) { Media media = mediaList.get(i); mAlbumsAdapter.add(media.getAlbum(), null, media); if (!lastAlbumName.equals(media.getAlbum())) { mSongsAdapter.addSeparator(media.getAlbum()); lastAlbumName = media.getAlbum(); } mSongsAdapter.add(media.getTitle(), null, media); } }
public void updateMeta(MediaPlayer mediaPlayer) { final Media media = mediaPlayer.getMedia(); if (media == null) return; updateMeta(media); media.release(); }
private static String getMetaId(Media media, int id, boolean trim) { String meta = media.getMeta(id); return meta != null ? trim ? meta.trim() : meta : null; }
/** * Create a new MediaWrapper * * @param media should be parsed and not NULL */ public MediaWrapper(Media media) { if (media == null) throw new NullPointerException("media was null"); mUri = media.getUri(); init(media); }
@Override public int compare(Media object1, Media object2) { return object1.getTitle().compareToIgnoreCase(object2.getTitle()); }
@Override public void onMediaAdded(int index, Media media) { if (media.getType() != Media.Type.Directory) return; super.onMediaAdded(index, media); }