更具体地说:我试图用jcodec的framegrab从res/raw加载视频。
framegrab需要seekablebitechannel,因此文件可以工作。
如何将资源中的视频文件作为文件获取?
我不能把视频放在SD卡上或其他类似的东西上,我正在为Android Wear开发。
编辑:

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());

最佳答案

最后我成功了。我不知道这是android特有的还是一个bug,但事实证明

String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
File file = new File(path);

不允许访问Android Wear设备上的文件。
相反,必须先将文件转换为临时文件:
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();
}

然后可以将其加载到视频视图中
mVideoView.setVideoPath(tmpFile.getPath());

如果您使用自己的视频解码器或像ffmpeg或vitamio这样的库,因为android wear还不支持本机视频播放。

10-07 19:28
查看更多