Reputation: 3440
More specific: I am trying to load a video from res/raw with jcodec's FrameGrab.
FrameGrab requires a SeekableBiteChannel, so a File will work.
How can I get a video file from assets as a File?
I cannot put the video on the sd-card or anything similar, I am developing for Android Wear.
EDIT:
String videoPath = "android.resource://" + getPackageName() + "/" + R.raw.hyperlapse2;
mVideoTestUri = Uri.parse(videoPath);
Log.d("VideoPlayer", "Video uri is " + mVideoTestUri);
File file = new File(videoPath);
Log.d("VideoPlayer", "Video file is " + file+", "+file.getName()+", "+file.getAbsolutePath()+", "+file.length());
Upvotes: 2
Views: 1211
Reputation: 3440
Finally I made it work. I don't know if this is something Android Wear specific or a bug, but it turns out that
String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
File file = new File(path);
does not give access to the file on Android Wear devices.
Instead one has to convert the file into a temp file first:
InputStream ins = MainActivityBackup.this.getResources().openRawResource (R.raw.hyperlapse2);
File tmpFile = null;
OutputStream output;
try {
tmpFile = File.createTempFile("video","mov");
output = new FileOutputStream(tmpFile);
final byte[] buffer = new byte[102400];
int read;
while ((read = ins.read(buffer)) != -1) {
output.write(buffer, 0, read);
}
output.flush();
output.close();
ins.close();
} catch (IOException e) {
e.printStackTrace();
}
And then it can be loaded into a videoView
mVideoView.setVideoPath(tmpFile.getPath());
Provided you are using your own video decoder or a library like ffmpeg or vitamio, since Android Wear does not support native video playback yet.
Upvotes: 4
Reputation: 1012
Place the video in the resource directory under a folder called raw.
String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
File file = new File(path);
VideoView view = (VideoView)findViewById(R.id.videoView);
view.setVideoURI(Uri.parse(path));
view.start();
Upvotes: 0