SD card in Android
In my app I have two buttons play and download. In the downlod button I download video from internet and store in SD card, i will play video from the SD card when press play button.
Video is successfully downloaded and stored in SD card. If I press play button, I will list videos from SD card(in logcat
) and play the downloaded video. It does not show the downloaded video name, but if I open开发者_运维百科 the SD card from my system the downloaded video is stored in SD card. i do not know where i am wrong.
You have to add media files to Media Store in order to be seen by gallery widget. Use MediaScanner. I use this convenient wrapper in my code:
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
}
}
Then instantiate MediaScannerWrapper
and start it with scan()
. You could tweak it to handle more than one file at the time. Hint: pass List of File paths, and then loop around mConnection.scanFile
.
精彩评论