use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by videolan.
the class MediaItemFilter method performFiltering.
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
final String[] queryStrings = charSequence.toString().trim().toLowerCase().split(" ");
FilterResults results = new FilterResults();
List<MediaLibraryItem> list = new ArrayList<>();
for (MediaLibraryItem item : initData()) {
for (String queryString : queryStrings) {
if (queryString.length() < 2)
continue;
if (item.getTitle() != null && item.getTitle().toLowerCase().contains(queryString)) {
list.add(item);
// avoid duplicates in search results, and skip useless processing
break;
}
}
}
results.values = list;
results.count = list.size();
return results;
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by videolan.
the class MusicFragment method onItemClicked.
@Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
MediaLibraryItem mediaLibraryItem = (MediaLibraryItem) item;
if (mediaLibraryItem.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
int position = 0;
for (int i = 0; i < mDataList.length; ++i) {
if (mediaLibraryItem.equals(mDataList[i])) {
position = i;
break;
}
}
TvUtil.playAudioList(mContext, (MediaWrapper[]) mDataList, position);
} else
TvUtil.openAudioCategory(mContext, mediaLibraryItem);
}
use of org.videolan.medialibrary.media.MediaLibraryItem 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;
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class CardPresenter method onBindViewHolder.
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, final Object item) {
final ViewHolder holder = ((ViewHolder) viewHolder);
if (item instanceof MediaWrapper) {
final MediaWrapper mw = (MediaWrapper) item;
holder.mCardView.setTitleText(mw.getTitle());
holder.mCardView.setContentText(mw.getDescription());
holder.updateCardViewImage(mw);
if (mIsSeenMediaMarkerVisible && mw.getType() == MediaWrapper.TYPE_VIDEO && mw.getSeen() > 0L)
holder.mCardView.setBadgeImage(ContextCompat.getDrawable(mContext, R.drawable.ic_seen_tv_normal));
holder.view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
TvUtil.INSTANCE.showMediaDetail(v.getContext(), mw);
return true;
}
});
} else if (item instanceof MediaLibraryItem) {
final MediaLibraryItem mediaLibraryItem = (MediaLibraryItem) item;
holder.mCardView.setTitleText(mediaLibraryItem.getTitle());
holder.mCardView.setContentText(mediaLibraryItem.getDescription());
holder.updateCardViewImage(mediaLibraryItem);
} else if (item instanceof SimpleCard) {
SimpleCard card = (SimpleCard) item;
Bitmap image = card.getImage();
holder.mCardView.setTitleText(card.getName());
holder.mCardView.setContentText(card.getDescription());
holder.updateCardViewImage(image != null ? new BitmapDrawable(mRes, image) : ContextCompat.getDrawable(mContext, card.getImageId()));
} else if (item instanceof String) {
holder.mCardView.setTitleText((String) item);
holder.mCardView.setContentText("");
holder.updateCardViewImage(sDefaultCardImage);
}
}
use of org.videolan.medialibrary.media.MediaLibraryItem in project vlc-android by GeoffreyMetais.
the class AudioAlbumsSongsFragment method onFabPlayClick.
@Override
@SuppressWarnings("unchecked")
public void onFabPlayClick(View view) {
final List<MediaWrapper> list;
if (mViewPager.getCurrentItem() == 0) {
list = new ArrayList<>();
for (MediaLibraryItem item : mAlbumsAdapter.getMediaItems()) list.addAll(Util.arrayToArrayList(item.getTracks()));
} else {
list = (List<MediaWrapper>) (List<?>) mSongsAdapter.getMediaItems();
}
MediaUtils.openList(getActivity(), list, 0);
}
Aggregations