Closed AdnanFakhar closed 6 years ago
Did you pass an empty url or invalid url?
I am doing in this way with full URL check...
if (listPlay == null || listPlay.size() < 1 || strIndex == null || listPlay.get(index).getMp3TrackUrl() == null){ Toast.makeText(DownloadService.this, "Cannot Download Song this time. Try later!!", Toast.LENGTH_SHORT).show(); stopForeground(true); stopSelf(); // Remove later }
else {
initNotification(index);
downloadMP3(index);
Toast.makeText(DownloadService.this, "Downloading Starts...", Toast.LENGTH_SHORT).show();
// new DownloadFileFromURL(index).execute(listPlay.get(index).getMp3TrackUrl());
}
if url is not null then it will call downloadMP3(index);
private void downloadMP3(final int position) { DownloadSongDB.getInstance().openDB(DownloadService.this); int ind = DownloadSongDB.getInstance().getDBSize() + 1; songFile = "koyal_" + ind + ".mp3"; DownloadSongDB.getInstance().closeDownloadSongDB();
File fileToDownload = new File(DownloadService.this.getFilesDir().getAbsolutePath() + "/" + songFile);
songFile = fileToDownload.getParent() + "/" + songFile;
Log.e(" download path ", songFile);
String url = listPlay.get(position).getMp3TrackUrl().replaceAll(" ", "%20");
Log.e("Download mp3 ", url);
downloadManager =
new DownloadManager.Builder().context(this)
.downloader(OkHttpDownloader.create())
.threadPoolSize(12)
.build();
DownloadRequest request = new DownloadRequest.Builder()
.url(url)
.retryTime(5)
.retryInterval(2, TimeUnit.SECONDS)
.progressInterval(1, TimeUnit.SECONDS)
.priority(Priority.HIGH)
.destinationFilePath(songFile)
.downloadCallback(new DownloadCallback() {.......
Could you pls provide the url, I want to thave a test on it.
I got the problem, it seems that your download got a redirection, but downloader did not get the Location
, then it crashed. I have fix this in #68 into develop branch.
Fatal Exception: java.lang.NullPointerException uriString
android.net.Uri$StringUri. (Uri.java:475)
android.net.Uri.parse (Uri.java:437)
com.coolerfall.download.OkHttpDownloader.innerRequest (OkHttpDownloader.java:113)
com.coolerfall.download.OkHttpDownloader.start (OkHttpDownloader.java:73)
com.coolerfall.download.DownloadDispatcher.executeDownload (DownloadDispatcher.java:197)
com.coolerfall.download.DownloadDispatcher.run (DownloadDispatcher.java:64)
I am getting this error.
Adnan