80,351
社区成员
发帖
与我相关
我的任务
分享
videoView.start();
/**
*
* @param videoView
* mvideoView
* @param mp4filename
* myvideo.mp4
*/
void playAssetsVideo(Context context, VideoView videoView, String mp4filename) {
try {
String filepath = Environment.getExternalStorageDirectory().getPath() + "/"
+ getResources().getString(R.string.app_name) + "/" + mp4filename;
copyFilesFassets(MainActivity.this, mp4filename, filepath);
InputStream is = context.getAssets().open(mp4filename);
FileOutputStream fos = new FileOutputStream(new File(filepath));
byte[] buffer = new byte[1024];
int byteCount = 0;
while ((byteCount = is.read(buffer)) != -1) {
fos.write(buffer, 0, byteCount);
}
fos.flush();
is.close();
fos.close();
videoView.setVideoPath(filepath);
videoView.setMediaController(new MediaController(MainActivity.this));
} catch (Exception e) {
e.printStackTrace();
}
}