【问题标题】:Android AsyncTask downloading .mp3 file - info and thumbnailAndroid AsyncTask 下载 .mp3 文件 - 信息和缩略图
【发布时间】:2017-07-06 11:27:56
【问题描述】:

我正在尝试从服务器下载 mp3 文件。 我成功制作了,可以播放文件,但是没有缩略图和文件信息,例如艺术家和专辑名称。

当我直接从 chrome 下载文件时,我上面提到的信息确实会被下载。 任何想法如何让它工作?

这是我的代码:

            URL url = new URL(urlDwn+urlVid);

            HttpURLConnection connection =(HttpURLConnection) url.openConnection();
            connection.connect();

            //file length
            int lengthOfFile = connection.getContentLength();
            //intput - read file
            InputStream inputStream = new BufferedInputStream(url.openStream(), 8192);

            //output - write file
            if(true) {
                System.out.println("Downloading");
                OutputStream outputStream = new FileOutputStream(root+"/"+fileName); 
                System.out.println(root+"/"+fileName);
                byte data[] = new byte[1024];
                long total = 0;
                while ((count = inputStream.read(data)) != -1) {
                    total += count;
                    //progress
                    publishProgress((int) ((total * 100) / lengthOfFile));

                    //writing to file
                    outputStream.write(data,0, count);
                }
                outputStream.flush();
                outputStream.close();
                inputStream.close();

【问题讨论】:

  • 可能是您检索缩略图和信息的方式有问题?
  • 如何找回?
  • 当您通过 chrome 下载它时,您确实会以某种方式检索它。
  • 但我不想为此使用 chrome。我将数据写入我创建的文件,并且音频效果很好。但我不明白为什么文件的拇指和信息不起作用。
  • 他们到底在哪里不工作?

标签: java android android-asynctask download mp3


【解决方案1】:

我解决了!

缩略图和 mp3 标签(艺术家等)似乎已正确下载。问题出在文件管理器本身(或者可能是安卓系统),所以当我重新启动设备时,它就出现了!

编辑

无需重新启动。您需要做的就是将以下几行添加到 onPostExecute 方法中,该方法告诉系统已添加了一个新文件。

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 2020-09-26
    • 2013-11-11
    • 2012-09-11
    相关资源
    最近更新 更多