fix issues with audio paths and download service
This commit is contained in:
parent
d2afefe595
commit
1b9c79ad5f
4 changed files with 23 additions and 9 deletions
|
|
@ -23,6 +23,7 @@ import java.net.URLConnection;
|
|||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public class DownloadService extends Service {
|
||||
public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID;
|
||||
public static final String EXTRA_SONG = PACKAGE_NAME + ".extra.song";
|
||||
|
|
@ -59,6 +60,8 @@ public class DownloadService extends Service {
|
|||
|
||||
download.getParentFile().mkdirs();
|
||||
download.createNewFile();
|
||||
audio.getParentFile().mkdirs();
|
||||
audio.createNewFile();
|
||||
|
||||
InputStream input = connection.getInputStream();
|
||||
OutputStream output = new FileOutputStream(download);
|
||||
|
|
@ -78,10 +81,14 @@ public class DownloadService extends Service {
|
|||
input = new FileInputStream(download);
|
||||
output = new FileOutputStream(audio);
|
||||
|
||||
output.write(input.read());
|
||||
while ((count = input.read(data)) != -1) {
|
||||
output.write(data, 0, count);
|
||||
}
|
||||
|
||||
input.close();
|
||||
output.close();
|
||||
|
||||
download.delete();
|
||||
App.getDatabase().cacheDao().insertCache(new Cache(song));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue