我怎样才能下载一首歌曲,并添加用户的音乐库?一首、音乐库、用户、歌曲

2023-09-06 11:18:05 作者:单身达人

我的Andr​​oid应用程序需要下载一个MP3曲目,并将其添加到用户的媒体库。

My Android app needs to download a MP3 track and add it to the user's media library.

我还没有找到任何这良好的文档,所以我在想,如果它是作为存储在音乐目录的MP3一样简单?如果是这样,这将是用户的音乐目录的位置?

I haven't found any good documentation on this so I was wondering if it is as simple as storing the MP3 in the Music directory? If so, what would be the location of the user's music directory?

推荐答案

使用 MediaScanner

String mp3path = "Your MP3 file path";   
MediaScannerConnection msc = new MediaScannerConnection(yourcontext,
        new MediaScannerConnection.MediaScannerConnectionClient() {
            @Override
            public void onScanCompleted(String path, Uri uri){
                msc.disconnect();
            }
            @Override
            public void onMediaScannerConnected() {
                msc.scanFile(mp3path, null);
            }           
        });             
msc.connect();