如何使标准的音乐播放器,找到我的文件 [英] How to make the standard music player find my files
本文介绍了如何使标准的音乐播放器,找到我的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用软件下载一些MP3文件到SD卡。我想与安装在设备上的其他音乐播放器播放它们。但是其他的音乐播放器不会自动找到我下载的文件。我怎样才能迫使MediaScanner这么运行的媒体文件会从股票音乐应用程序上播放?
我下载使用这个code中的文件
公共无效的run(){
装载= 0;
尝试{
在java.io.BufferedInputStream中=新java.io.BufferedInputStream中(新的java.net.URL(URL).openStream());
java.io.FileOutputStream中的FOS =新java.io.FileOutputStream中(文件名);
java.io.BufferedOutputStream回合=新的BufferedOutputStream(FOS,1024);
字节[]数据=新的字节[1024];
INT X = 0;
而((X = in.read(数据,0,1024))> = 0&放大器;&安培;!停止){
装+ = X;
bout.write(数据,0,x)的;
}
fos.flush();
bout.flush();
fos.close();
bout.close();
附寄(); }赶上(例外五){ }
}
解决方案
您可以强制媒体文件的扫描与广播:
sendBroadcast(新意图(Intent.ACTION_MEDIA_MOUNTED,Uri.parse(文件://+ Environment.getExternalStorageDirectory())));
My App downloads some mp3 files to sdcard. I want to play them with other music players installed on the device. But the other music players don't automatically find my downloaded files. How can I force the MediaScanner to run so that my media files will be playable from the stock Music application?
I download the files using this code
public void run() {
loaded = 0;
try{
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(url).openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(FileName);
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
byte[] data = new byte[1024];
int x=0;
while((x=in.read(data,0,1024))>=0 && !stop){
loaded += x;
bout.write(data,0,x);
}
fos.flush();
bout.flush();
fos.close();
bout.close();
in.close();
}catch(Exception e){
}
}
解决方案
You can force the scan of media file with a broadcast:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
这篇关于如何使标准的音乐播放器,找到我的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文