private static String getCoverFromVlc(Context context, Media media) throws NoSuchAlgorithmException, UnsupportedEncodingException { String artworkURL = media.getArtworkURL(); if (artworkURL != null && artworkURL.startsWith("file://")) { return Uri.decode(artworkURL).replace("file://", ""); } else if (artworkURL != null && artworkURL.startsWith("attachment://")) { // Decode if the album art is embedded in the file String mArtist = media.getArtist(); String mAlbum = media.getAlbum(); /* Parse decoded attachment */ if (mArtist.length() == 0 || mAlbum.length() == 0 || mArtist.equals(VLCApplication.getAppContext().getString(R.string.unknown_artist)) || mAlbum.equals(VLCApplication.getAppContext().getString(R.string.unknown_album))) { /* If artist or album are missing, it was cached by title MD5 hash */ MessageDigest md = MessageDigest.getInstance("MD5"); byte[] binHash = md.digest((artworkURL + media.getTitle()).getBytes("UTF-8")); /* Convert binary hash to normal hash */ BigInteger hash = new BigInteger(1, binHash); String titleHash = hash.toString(16); while (titleHash.length() < 32) { titleHash = "0" + titleHash; } /* Use generated hash to find art */ artworkURL = CACHE_DIR + "/art/arturl/" + titleHash + "/art.png"; } else { /* Otherwise, it was cached by artist and album */ artworkURL = CACHE_DIR + "/art/artistalbum/" + mArtist + "/" + mAlbum + "/art.png"; } return artworkURL; } return null; }
public static void setSleep(Calendar time) { AlarmManager alarmMgr = (AlarmManager) VLCApplication.getAppContext().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(VLCApplication.SLEEP_INTENT); PendingIntent sleepPendingIntent = PendingIntent.getBroadcast( VLCApplication.getAppContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); if (time != null) { alarmMgr.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), sleepPendingIntent); } else { alarmMgr.cancel(sleepPendingIntent); } VLCApplication.sPlayerSleepTime = time; }
public static boolean isCallable(Intent intent) { List<ResolveInfo> list = VLCApplication.getAppContext() .getPackageManager() .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
public static String[] getCustomDirectories() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()); final String custom_paths = preferences.getString("custom_paths", ""); if (custom_paths.equals("")) return new String[0]; else return custom_paths.split(":"); }
public static String readAsset(String assetName, String defaultS) { InputStream is = null; BufferedReader r = null; try { is = VLCApplication.getAppResources().getAssets().open(assetName); r = new BufferedReader(new InputStreamReader(is, "UTF8")); StringBuilder sb = new StringBuilder(); String line = r.readLine(); if (line != null) { sb.append(line); line = r.readLine(); while (line != null) { sb.append('\n'); sb.append(line); line = r.readLine(); } } return sb.toString(); } catch (IOException e) { return defaultS; } finally { close(is); close(r); } }
private String getVisibleName(File file) { if (android.os.Build.VERSION.SDK_INT >= 17) { // Show "sdcard" for the user's folder when running in multi-user if (file.getAbsolutePath().equals(Environment.getExternalStorageDirectory().getPath())) { return VLCApplication.getAppContext().getString(R.string.internal_memory); } } return file.getName(); }
private void DirectoryAdapter_Core(String rootDir) { if (rootDir != null) rootDir = Util.stripTrailingSlash(rootDir); Log.v(TAG, "rootMRL is " + rootDir); mInflater = LayoutInflater.from(VLCApplication.getAppContext()); mRootNode = new DirectoryAdapter.Node(rootDir); mCurrentDir = rootDir; this.populateNode(mRootNode, rootDir); mCurrentNode = mRootNode; }
public static int convertPxToDp(int px) { WindowManager wm = (WindowManager) VLCApplication.getAppContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); float logicalDensity = metrics.density; int dp = Math.round(px / logicalDensity); return dp; }
public static boolean isPhone() { TelephonyManager manager = (TelephonyManager) VLCApplication.getAppContext().getSystemService(Context.TELEPHONY_SERVICE); if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) { return false; } else { return true; } }
@Override public View getView(int position, View convertView, ViewGroup parent) { DirectoryAdapter.Node selectedNode = mCurrentNode.children.get(position); DirectoryViewHolder holder; View v = convertView; Context context = VLCApplication.getAppContext(); /* If view not created */ if (v == null) { v = mInflater.inflate(R.layout.directory_view_item, parent, false); holder = new DirectoryViewHolder(); holder.layout = v.findViewById(R.id.layout_item); holder.title = (TextView) v.findViewById(R.id.title); holder.text = (TextView) v.findViewById(R.id.text); holder.icon = (ImageView) v.findViewById(R.id.dvi_icon); v.setTag(holder); } else holder = (DirectoryViewHolder) v.getTag(); Util.setItemBackground(holder.layout, position); String holderText = ""; if (selectedNode.isFile()) { Log.d(TAG, "Loading media " + selectedNode.name); Media m = new Media(getMediaLocation(position), false); holder.title.setText(m.getTitle()); holderText = m.getSubtitle(); } else holder.title.setText(selectedNode.getVisibleName()); if (selectedNode.name == "..") holderText = context.getString(R.string.parent_folder); else if (!selectedNode.isFile()) { int folderCount = selectedNode.subfolderCount(); int mediaFileCount = selectedNode.subfilesCount(); holderText = ""; if (folderCount > 0) holderText += context .getResources() .getQuantityString(R.plurals.subfolders_quantity, folderCount, folderCount); if (folderCount > 0 && mediaFileCount > 0) holderText += ", "; if (mediaFileCount > 0) holderText += context .getResources() .getQuantityString(R.plurals.mediafiles_quantity, mediaFileCount, mediaFileCount); } holder.text.setText(holderText); if (selectedNode.isFile()) holder.icon.setImageResource(R.drawable.icon); else holder.icon.setImageResource(R.drawable.ic_folder); return v; }
public static LibVLC getLibVlcInstance() throws LibVlcException { LibVLC instance = LibVLC.getExistingInstance(); if (instance == null) { Thread.setDefaultUncaughtExceptionHandler(new VlcCrashHandler()); instance = LibVLC.getInstance(); Context context = VLCApplication.getAppContext(); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); updateLibVlcSettings(pref); instance.init(context); } return instance; }
public static void addCustomDirectory(String path) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()); ArrayList<String> dirs = new ArrayList<String>(Arrays.asList(getCustomDirectories())); dirs.add(path); StringBuilder builder = new StringBuilder(); builder.append(dirs.remove(0)); for (String s : dirs) { builder.append(":"); builder.append(s); } SharedPreferences.Editor editor = preferences.edit(); editor.putString("custom_paths", builder.toString()); editor.commit(); }
private void savePlaylist() { VLCApplication.runBackground( new Runnable() { public void run() { final MediaDatabase db = MediaDatabase.getInstance(); final String name = mEditText.getText().toString().trim(); if (db.playlistExists(name)) db.playlistDelete(name); db.playlistAdd(name); MediaWrapper mw; for (int i = 0; i < mTracks.size(); ++i) { mw = mTracks.get(i); db.playlistInsertItem(name, i, mw.getLocation()); } } }); dismiss(); }
public Bitmap getPicture() { // mPicture is not null only if passed through // the ctor which is deprecated by now. if (mPicture == null) { BitmapCache cache = BitmapCache.getInstance(); Bitmap picture = cache.getBitmapFromMemCache(mLocation); 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 = DatabaseManager.getInstance(c).getPicture(c, mLocation); cache.addBitmapToMemCache(mLocation, picture); } return picture; } else { return mPicture; } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static boolean deleteFile(String path) { boolean deleted = false; path = Uri.decode(Strings.removeFileProtocole(path)); // Delete from Android Medialib, for consistency with device MTP storing and other apps listing // content:// media if (AndroidUtil.isHoneycombOrLater()) { ContentResolver cr = VLCApplication.getAppContext().getContentResolver(); String[] selectionArgs = {path}; deleted = cr.delete( MediaStore.Files.getContentUri("external"), MediaStore.Files.FileColumns.DATA + "=?", selectionArgs) > 0; } File file = new File(path); if (file.exists()) deleted |= file.delete(); return deleted; }
/** * Create a new Media * * @param context Application context of the caller * @param media URI * @param addToDb Should it be added to the file database? */ public Media(String URI, Boolean addToDb) { mLocation = URI; LibVLC mLibVlc = null; try { mLibVlc = LibVLC.getInstance(); mType = TYPE_ALL; TrackInfo[] tracks = mLibVlc.readTracksInfo(mLocation); extractTrackInfo(tracks); } catch (LibVlcException e) { e.printStackTrace(); } if (addToDb) { // Add this item to database DatabaseManager db = DatabaseManager.getInstance(VLCApplication.getAppContext()); db.addMedia(this); } }
public static void removeCustomDirectory(String path) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()); if (!preferences.getString("custom_paths", "").contains(path)) return; ArrayList<String> dirs = new ArrayList<String>(Arrays.asList(preferences.getString("custom_paths", "").split(":"))); dirs.remove(path); String custom_path; if (dirs.size() > 0) { StringBuilder builder = new StringBuilder(); builder.append(dirs.remove(0)); for (String s : dirs) { builder.append(":"); builder.append(s); } custom_path = builder.toString(); } else { // don't do unneeded extra work custom_path = ""; } SharedPreferences.Editor editor = preferences.edit(); editor.putString("custom_paths", custom_path); editor.commit(); }
public static int convertDpToPx(int dp) { return Math.round( TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, dp, VLCApplication.getAppResources().getDisplayMetrics())); }
public static void actionScanStop() { Intent intent = new Intent(); intent.setAction(ACTION_SCAN_STOP); VLCApplication.getAppContext().sendBroadcast(intent); }
/** @return the main resources from the Application */ public static Resources getAppResources() { if (instance == null) return null; return instance.getResources(); }
public static int convertPxToDp(int px) { DisplayMetrics metrics = VLCApplication.getAppResources().getDisplayMetrics(); float logicalDensity = metrics.density; int dp = Math.round(px / logicalDensity); return dp; }
public static String getValue(String string, int defaultId) { return (string != null && string.length() > 0) ? string : VLCApplication.getAppContext().getString(defaultId); }
public String getGenre() { if (mGenre == VLCApplication.getAppContext().getString(R.string.unknown_genre)) return mGenre; else /* Make genres case insensitive via normalisation */ return Character.toUpperCase(mGenre.charAt(0)) + mGenre.substring(1).toLowerCase(); }
/** * Get a color id from an attribute id. * * @param context * @param attrId * @return the color id */ public static int getColorFromAttribute(Context context, int attrId) { return VLCApplication.getAppResources().getColor(getResourceFromAttribute(context, attrId)); }