[英]Download Mp3 Files (Android)
I have Application play some mp3 files from the internet and I want to add "Download Button" to download any mp3 file from the internet I want to download from the browser ,,, not from Application ,,, but if I want to call the browser such as : 我让Application从Internet播放一些mp3文件,并且我想添加“下载按钮”以从Internet下载我想从浏览器下载的任何mp3文件,而不是从Application,但是如果我要调用浏览器,例如:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("xxxx.xxxx.xxxx.mp3"))); startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(“ xxxx.xxxx.xxxx.mp3”)));;
the browser going to play this mp3 file :( 浏览器将播放此mp3文件:(
I think I can add thing after the link to download directly ,,,, any one can help me ? 我想我可以在链接后添加东西以直接下载,,,任何人都可以帮助我吗?
Note : if you have a code to download from the App ,,, tell me about it also :) I'm new in android world :P and I want a simple code to can understand it thank you all :) 注意:如果您有要从App下载的代码,请告诉我有关的信息:)我是android world的新手:P,并且我希望有一个简单的代码可以理解它,谢谢大家:)
You would be better off using the DownloadManager . 使用DownloadManager会更好。 You can see example code by Lars Vogel here
您可以在此处查看Lars Vogel的示例代码
The relevant bit: 相关位:
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
Request request = new Request(
Uri.parse("http://www.vogella.de/img/lars/LarsVogelArticle7.png"));
enqueue = dm.enqueue(request);
Note that DownloadManager is available on API version 9 (Android 2.3, Gingerbread) and upwards. 请注意,DownloadManager在API版本9(Android 2.3,Gingerbread)及更高版本上可用。
You can put this in your download.php file 您可以将其放在您的download.php文件中
<?php
$file = $_GET['file'];
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>
and then: 接着:
Uri.parse("direct_download.php?file=filename.mp3");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.