在我的应用程序中,我有两个按钮播放和下载。在下载按钮中,我从互联网上下载视频并存储在SD卡中,当按下播放按钮时,我将播放SD卡中的视频。
视频下载成功,并存储在SD卡中。如果我按下播放按钮,我将列出SD卡(logcat
格式)中的视频并播放下载的视频。它不显示下载的视频名称,但如果我从我的系统打开SD卡,下载的视频将存储在SD卡中。我不知道我错在哪里。
发布于 2011-06-26 15:45:26
您必须将媒体文件添加到media Store,才能被多媒体库小工具看到。使用MediaScanner。我在代码中使用了这个方便的包装器:
public class MediaScannerWrapper implements
MediaScannerConnection.MediaScannerConnectionClient {
private MediaScannerConnection mConnection;
private String mPath;
private String mMimeType;
// filePath - where to scan;
// mime type of media to scan i.e. "image/jpeg".
// use "*/*" for any media
public MediaScannerWrapper(Context ctx, String filePath, String mime){
mPath = filePath;
mMimeType = mime;
mConnection = new MediaScannerConnection(ctx, this);
}
// do the scanning
public void scan() {
mConnection.connect();
}
// start the scan when scanner is ready
public void onMediaScannerConnected() {
mConnection.scanFile(mPath, mMimeType);
Log.w("MediaScannerWrapper", "media file scanned: " + mPath);
}
public void onScanCompleted(String path, Uri uri) {
// when scan is completes, update media file tags
}
}
然后用scan()
实例化MediaScannerWrapper
并启动它。您可以调整它以同时处理多个文件。提示:传递文件路径列表,然后循环mConnection.scanFile
。
https://stackoverflow.com/questions/6482751
复制相似问题