下载带有元数据/属性(例如标题、艺术家等)的 mp3

发布于 2024-12-27 22:01:27 字数 1379 浏览 1 评论 0原文

我有以下代码。一切工作正常,除了当我使用默认音乐播放器播放时,下载的 MP3 文件没有任何属性(元数据),例如艺术家、标题等。如果尝试使用 Android 浏览器直接从网站下载相同的 mp3 文件并使用默认音乐播放器播放,则所有元数据都完好无损(即音乐播放器显示标题、艺术家等)。

    @Override
    protected String doInBackground(String... aurl) {
        int count;

        i = Integer.parseInt(aurl[0]);
        try {
            sura = "abc.mp3";
            String addr = "http://www.xyzabc.com/" + sura;

            URL url = new URL(addr);
            HttpURLConnection conexion = (HttpURLConnection) url.openConnection();
              conexion.setRequestMethod("GET");
                conexion.setDoOutput(true);
            conexion.connect();

            int lenghtOfFile = conexion.getContentLength();

            InputStream input = new BufferedInputStream(url.openStream());
            File file = new File(rootDir + "/mysite/" + sura);
            OutputStream output = new FileOutputStream(file);

            byte data[] = new byte[1024];

            long total = 0;

            while ((count = input.read(data)) != -1 & run == true) {
                total += count;
                publishProgress("" + (int) ((total * 100) / lenghtOfFile));
                output.write(data, 0, count);
            }

            output.flush();
            output.close();
            input.close();

        } catch (Exception e) {
        }

        return null;
    }

I have the following code. Everything works fine except that the downloded MP3 file does not have any property (metadata) such as Artist, title and etc when I play using the default music player. If tried to download the same mp3 file from the site directly using android browser and play using the default music player, all the metatdata are intact (ie. music player display title, artist and etc).

    @Override
    protected String doInBackground(String... aurl) {
        int count;

        i = Integer.parseInt(aurl[0]);
        try {
            sura = "abc.mp3";
            String addr = "http://www.xyzabc.com/" + sura;

            URL url = new URL(addr);
            HttpURLConnection conexion = (HttpURLConnection) url.openConnection();
              conexion.setRequestMethod("GET");
                conexion.setDoOutput(true);
            conexion.connect();

            int lenghtOfFile = conexion.getContentLength();

            InputStream input = new BufferedInputStream(url.openStream());
            File file = new File(rootDir + "/mysite/" + sura);
            OutputStream output = new FileOutputStream(file);

            byte data[] = new byte[1024];

            long total = 0;

            while ((count = input.read(data)) != -1 & run == true) {
                total += count;
                publishProgress("" + (int) ((total * 100) / lenghtOfFile));
                output.write(data, 0, count);
            }

            output.flush();
            output.close();
            input.close();

        } catch (Exception e) {
        }

        return null;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

A君 2025-01-03 22:01:27

下载完成后,系统内容提供程序不会立即更新。
尝试重新启动模拟器或安装/卸载 SD 卡,查看内容提供商是否更新。

uri 为 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,您可以通过查询 MediaStore.Audio.Media.DATA、MediaStore.Audio.Media.TITLE 获取详细信息,
MediaStore.Audio.Media.COMPOSER、MediaStore.Audio.Media.ALBUM、
MediaStore.Audio.Media.ARTIST
和其他(全部在 MediaStore.Audio.Media.* 中)

如果您想立即获取信息,也许您应该自己更新 Content Provider 手册。

The System content provider didn't update as soon as your downloading complete.
Try restart your emulator or install/unstall your sd card, see if the content provider updates.

The uri is MediaStore.Audio.Media.EXTERNAL_CONTENT_URI and you can get details by query MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.COMPOSER, MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ARTIST
and others (All in MediaStore.Audio.Media.*)

If you want to get the information immediately, maybe you should update the Content Provider manual by yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文