use of com.frostwire.platform.FileSystem in project frostwire by frostwire.
the class MusicUtils method deleteTracks.
/**
* Permanently deletes item(s) from the user's device.
*
* @param context The {@link Context} to use.
* @param list The item(s) to delete.
*/
public static void deleteTracks(final Context context, final long[] list, boolean showNotification) {
if (list == null) {
return;
}
final String[] projection = new String[] { BaseColumns._ID, MediaColumns.DATA, AudioColumns.ALBUM_ID };
final StringBuilder selection = new StringBuilder();
selection.append(BaseColumns._ID + " IN (");
for (int i = 0; i < list.length; i++) {
selection.append(list[i]);
if (i < list.length - 1) {
selection.append(",");
}
}
selection.append(")");
final Cursor c = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection.toString(), null, null);
if (c != null) {
// Step 1: Remove selected tracks from the current playlist, as well
// as from the album art cache
c.moveToFirst();
while (!c.isAfterLast()) {
// Remove from current playlist.
final long id = c.getLong(0);
removeTrack(id);
// Remove from the favorites playlist.
FavoritesStore.getInstance(context).removeItem(id);
// Remove any items in the recent's database
RecentStore.getInstance(context).removeItem(id);
// Remove from all remaining playlists.
removeSongFromAllPlaylists(context, id);
c.moveToNext();
}
// Step 2: Remove selected tracks from the database
context.getContentResolver().delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, selection.toString(), null);
// Step 3: Remove files from card
FileSystem fs = Platforms.fileSystem();
c.moveToFirst();
while (!c.isAfterLast()) {
final String name = c.getString(1);
try {
// File.delete can throw a security exception
final File f = new File(name);
if (!fs.delete(f)) {
// I'm not sure if we'd ever get here (deletion would
// have to fail, but no exception thrown)
Log.e("MusicUtils", "Failed to delete file " + name);
}
c.moveToNext();
} catch (final Throwable ex) {
c.moveToNext();
}
}
c.close();
UIUtils.broadcastAction(context, Constants.ACTION_FILE_ADDED_OR_REMOVED, new UIUtils.IntentByteExtra(Constants.EXTRA_REFRESH_FILE_TYPE, Constants.FILE_TYPE_AUDIO));
}
if (showNotification) {
try {
final String message = makeLabel(context, R.plurals.NNNtracksdeleted, list.length);
AppMsg.makeText(context, message, AppMsg.STYLE_CONFIRM).show();
} catch (Throwable ignored) {
}
}
// We deleted a number of tracks, which could affect any number of
// things
// in the media content domain, so update everything.
context.getContentResolver().notifyChange(Uri.parse("content://media"), null);
// Notify the lists to update
refresh();
}
use of com.frostwire.platform.FileSystem in project frostwire by frostwire.
the class AndroidPlatform method buildFileSystem.
private static FileSystem buildFileSystem(Application app) {
FileSystem fs;
if (Build.VERSION.SDK_INT >= VERSION_CODE_LOLLIPOP) {
LollipopFileSystem lfs = new LollipopFileSystem(app);
PosixCalls w = new PosixCalls(lfs);
w.swigReleaseOwnership();
libtorrent.set_posix_wrapper(w);
// LibTorrent.setPosixWrapper(new PosixCalls(lfs));
fs = lfs;
} else {
fs = new DefaultFileSystem() {
@Override
public void scan(File file) {
Librarian.instance().scan(app, file);
}
};
}
return fs;
}
use of com.frostwire.platform.FileSystem in project frostwire by frostwire.
the class BaseHttpDownload method remove.
@Override
public void remove(boolean deleteData) {
if (complete) {
return;
}
complete(state = TransferState.CANCELED);
FileSystem fs = Platforms.fileSystem();
if (fs.delete(tempPath)) {
LOG.warn("Error deleting temporary file: " + tempPath);
}
if (deleteData) {
if (fs.delete(savePath)) {
LOG.warn("Error deleting download data file: " + savePath);
}
}
}
use of com.frostwire.platform.FileSystem in project frostwire by frostwire.
the class YouTubeDownload method onHttpComplete.
@Override
protected void onHttpComplete() throws Throwable {
boolean callSuper = true;
if (downloadType == DownloadType.DASH) {
FileSystem fs = Platforms.fileSystem();
if (fs.exists(tempVideo) && !fs.exists(tempAudio)) {
start(sr.getAudio().link, tempAudio, false);
callSuper = false;
}
}
if (callSuper) {
super.onHttpComplete();
}
}
use of com.frostwire.platform.FileSystem in project frostwire by frostwire.
the class YouTubeDownload method onFinishing.
@Override
protected void onFinishing() throws Throwable {
if (downloadType == DownloadType.VIDEO) {
removeUdta(tempVideo);
moveAndComplete(tempVideo, savePath);
} else if (downloadType == DownloadType.DEMUX) {
state = TransferState.DEMUXING;
Mp4Demuxer.audio(tempAudio.getAbsoluteFile(), tempPath, buildMp4Info(true), readCount -> demuxerReadCount = readCount);
moveAndComplete(tempPath, savePath);
FileSystem fs = Platforms.fileSystem();
if (!fs.delete(tempAudio)) {
LOG.warn("Error deleting temporary audio file: " + tempAudio);
}
} else if (downloadType == DownloadType.DASH) {
// intentionally not using FileSystem here
if (tempVideo.exists() && tempAudio.exists()) {
state = TransferState.DEMUXING;
Mp4Demuxer.muxFragments(tempVideo.getAbsoluteFile(), tempAudio.getAbsoluteFile(), tempPath.getAbsoluteFile(), buildMp4Info(false), null);
moveAndComplete(tempPath, savePath);
FileSystem fs = Platforms.fileSystem();
if (!fs.delete(tempVideo)) {
LOG.warn("Error deleting temporary video file: " + tempVideo);
}
if (!fs.delete(tempAudio)) {
LOG.warn("Error deleting temporary audio file: " + tempAudio);
}
} else {
complete(TransferState.ERROR);
}
}
}
Aggregations