Android 视频播放器总结,一口气拿了9家公司的offer
作者:互联网
case R.id.btnNext:
if (videoPosition + 1 < MyApp.arrayListVideo.size()) {
playVideoByPosition(videoPosition + 1);
cancelDelayHide();
hideControllerDelay();
} else {
HintUtil.showToast(context,
getString(R.string.video_play_alredy_last));
}
break;
case R.id.btnPrevious:
if (videoPosition - 1 >= 0
&& videoPosition - 1 < MyApp.arrayListVideo.size()) {
playVideoByPosition(videoPosition - 1);
cancelDelayHide();
hideControllerDelay();
} else {
HintUtil.showToast(context,
getString(R.string.video_play_alredy_first));
}
break;
case R.id.btnPlayState:
cancelDelayHide();
if (isPaused) {
videoView.start();
btnPlayState.setImageResource(R.drawable.btn_video_pause);
hideControllerDelay();
} else {
videoView.pause();
btnPlayState.setImageResource(R.drawable.btn_video_play);
}
isPaused = !isPaused;
break;
![这里写图片描述](https://www.icode9.com/i/?i=20170317141852272?/gravity/SouthEast)
获取指定目录的视频文件:
public static ArrayList getVideos(ContentResolver cr,
boolean isFront, boolean isLock) {
ArrayList arrayListVideo = new ArrayList();
File dirMedia;
if (!isFront) { // 后录视频
-
dirMedia = new File(isLock ? Constant.Path.VIDEO_BACK_LOCK
- Constant.Path.VIDEO_BACK_UNLOCK);
} else { // 前录视频
-
dirMedia = new File(isLock ? Constant.Path.VIDEO_FRONT_LOCK
- Constant.Path.VIDEO_FRONT_UNLOCK);
}
try {
if (dirMedia.exists()) {
File[] childFiles = dirMedia.listFiles();
for (File childFile : childFiles) {
String fileName = childFile.getName();
if (!fileName.startsWith(".") && fileName.endsWith(".mp4")
&& childFile.exists()) {
MultiGridItem item = new MultiGridItem();
item.path = childFile.getPath();
item.isVideo = true;
item.displayName = childFile.getName();
String thumbnailPath = Constant.Path.VIDEO_THUMBNAIL
- fileName.replace(".mp4", “.jpg”);
if (new File(thumbnailPath).exists()) {
item.thumbnail = “file://” + thumbnailPath;
} else {
item.bitmapThumbnail = getVideoThumbnail(
childFile.getPath(), 96, 96,
MediaStore.Video.Thumbnails.MICRO_KIND);
}
arrayListVideo.add(item);
}
}
} else {
MyLog.i(“getVideos.Directory not exist”);
}
} catch (Exception e) {
e.printStackTrace();
MyLog.e(“getVideos catch Exception:” + e.toString());
}
Collections.reverse(arrayListVideo);
return arrayListVideo;
}
获取照片:
public static ArrayList getPhotos(ContentResolver resolver,
boolean isFront) {
ArrayList galleryList = new ArrayList();
try {
final String[] columns = { MediaStore.Images.Media.DATA,
MediaStore.Images.Media._ID };
final String orderBy = MediaStore.Images.Media._ID;
Cursor imagecursor = resolver.query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns,
null, null, orderBy);
if (imagecursor != null && imagecursor.getCount() > 0) {
while (imagecursor.moveToNext()) {
MultiGridItem item = new MultiGridItem();
int dataColumnIndex = imagecursor
.getColumnIndex(MediaStore.Images.Media.DATA);
String imagePath = imagecursor.getString(dataColumnIndex);
item.path = “file://” + imagePath;
// DATA:/storage/sdcard1/DrivingRecord/Image/2017-03-09_150926_1.jpg
if (imagePath
.startsWith("/storage/sdcard1/DrivingRecord/Image/20")) {
item.displayName = imagePath.split("/")[5];
}
if (item.path.endsWith(isFront ? “_0.jpg” : “_1.jpg”)) {
galleryList.add(item);
}
}
}
} catch (Exception e) {
e.printStackTrace();
MyLog.e(“getPhotos catch Exception:” + e.toString());
}
// show newest photo at beginning of the list
Collections.reverse(galleryList);
return galleryList;
}
删除对话框:
private void showDeleteProgressDialog(String[] paths) {
final int itemSize = paths.length;
final String[] itemPaths = paths;
if (itemSize > 0) {
final ProgressDialog dialog = new ProgressDialog(context);
dialog.setTitle(getString(R.string.dialog_delete_title));
dialog.setMessage(getString(R.string.dialog_delete_wait));
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMax(itemSize);
dialog.setCancelable(false);
dialog.show();
dialog.setProgress(0);
new Thread() {
public void run() {
for (int i = 0; i < itemSize; i++) {
String path = itemPaths[i];
if (path != null) {
File fileDelete = new File(path);
if (fileDelete.exists() && fileDelete.isFile()) {
fileDelete.delete();
}
dialog.setProgress(i + 1);
}
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
HintUtil.showToast(context, context.getResources()
.getString(R.string.dialog_delete_success));
dialog.dismiss();
reloadContent();
}
});
}
}.start();
}
}
加锁对话框:
private void showLockProgressDialog(String[] paths) {
final int itemSize = paths.length;
标签:播放器,String,offer,File,item,dialog,new,Android,MediaStore 来源: https://blog.csdn.net/m0_66144836/article/details/122491698