获取视频
ContentResolver resolver = getContentResolver();
Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] objs = {
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.DURATION,
MediaStore.Video.Media.SIZE,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.ARTIST
};
Cursor cursor = resolver.query(uri, objs, null, null, null);
if (cursor != null) {
while (cursor.moveToNext()){
String name = cursor.getString(0);
long duration = cursor.getLong(1);
long size = cursor.getLong(2);
long data = cursor.getLong(3);
long artist = cursor.getLong(4);
}
}
cursor.close();
简单播放
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
mVideoView = (VideoView) findViewById(R.id.videoView);
String path = "http://192.168.2.217/[Vmoe]Kurikaeshi%20no%20hitotsubu.mp4";
mVideoView.setVideoPath(path);
/**
* 设置状态监听
*/
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Toast.makeText(MyVideoActivity.this, "播放失败", Toast.LENGTH_SHORT).show();
return false;
}
});
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Toast.makeText(MyVideoActivity.this, "播放结束", Toast.LENGTH_SHORT).show();
}
});
mVideoView.setMediaController(new MediaController(this));