res/raw/start.mp4||apple.mp3
注意:在文件比较小的时候可以直接使用,而在文件比较大的时候就需要将文件拷贝到手机存储中然后再进行操作
public class FileHelper {
private Context context;
public FileHelper(Context context) {
this.context = context;
}
public boolean fileIsExists() {
try {
File f = new File(Environment.getExternalStorageDirectory()+ "/start.mp4");
if (!f.exists()) {
return false;
}
} catch (Exception e) {
// TODO: handle exception
return false;
}
return true;
}
public void copyFile() {
InputStream in = context.getResources().openRawResource(R.raw.start);
byte[] buff = new byte[10 * 1024];
int length = 0;
try {
FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory()+ "/start.mp4");
System.out.println("拷贝文件路径:"+ Environment.getExternalStorageDirectory().getPath()+ "/start.mp4");
while ((length = in.read(buff)) != -1) {
out.write(buff, 0, length);
out.flush();
}
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
mp = MediaPlayer.create(WishActivity.this, R.raw.apple);
try {
mp.prepare();
} catch (Exception e) {
}
mp.start();
mp.setLooping(true);