gpt4 book ai didi

java - 如何通过 URL 从 firebase 数据库下载音频文件 mp3 或 mp4 或 mpeg

转载 作者:行者123 更新时间:2023-11-30 04:53:48 25 4
gpt4 key购买 nike

在我的类适配器中,我有 ImageView,它必须根据扩展名 mp3、mp4-mpeg 下载歌曲。我的 firebase 数据库如下所示:

my database picture witch musicUrl

我不明白为什么下载没有开始这是方法:

private void musicdownload(String uri, String title){
try {

File musicStorageDir = new File(Environment.getExternalStoragePublicDirectory(DIRECTORY_MUSIC), "Gladia");

if (!musicStorageDir.exists()){
musicStorageDir.mkdir();

}

//Default Extension mp3
String musicExtension = ".mp3";
if (uri.contains(".mp4")){
musicExtension = ".mp4";
}else if (uri.contains(".aac")){
musicExtension = ".aac";
}else if (uri.contains(".mpeg")){
musicExtension = ".mpeg";
}

String singName = title + musicExtension;

DownloadManager downloadManager = (DownloadManager)mContext.getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(uri);

Log.d(TAG, "musicdownload: downloadUri: " + downloadUri);
DownloadManager.Request request = new DownloadManager.Request(downloadUri);

request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setDestinationInExternalPublicDir(DIRECTORY_MUSIC + File.separator, singName)
.setTitle(singName).setDescription(title)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

downloadManager.enqueue(request);


}catch (Exception e){
e.printStackTrace();
}
}

方法调用

    viewHolder.download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

musicdownload(music.getMusicUrl(), music.getMusicTitle());
}
});

最佳答案

谢谢,我看到了问题。我没有激活授权。

关于java - 如何通过 URL 从 firebase 数据库下载音频文件 mp3 或 mp4 或 mpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59571922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com