把 video 放在 apk 包中, 可以方便程序的安装,有两种读取的方法
从包中拆解文件再读取
video 文件放在 Prj_Dir/assets 下 ( Prj_Dir/assets/myvideo.mp4)
public class VideoActivity extends Activity {
public final String TAG = "VideoActivity";
private final String VIDEO = "myvideo.mp4";
public boolean storeVideoFile() {
try {
InputStream is = getResources().getAssets().open(VIDEO);
//注意,这里用 MODE_WORLD_READABLE 是因为播放Video的是MediaPlayer进程,不是本进程
//为了让, MediaPlayer进程能读取此文件,所以设置为: MODE_WORLD_READABLE
FileOutputStream os = openFileOutput(VIDEO, MODE_WORLD_READABLE);
byte[] buffer = new byte[1024];
while (is.read(buffer) > -1) {
os.write(buffer);
}
is.close();
os.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
r