我正在尝试将我的图像转换成视频。我找到了示例代码并将其用于我的应用程序。但是我收到了这样的错误
java.io.FileNotFoundException: output.mp4(只读文件系统)
这是我的代码 fragment :
public class Main2Activity extends AppCompatActivity {
AndroidSequenceEncoder encoder;
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
ArrayList<Bitmap> arrayList = new ArrayList<>();
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.empty_collage);
Bitmap a = BitmapFactory.decodeResource(getResources(),R.drawable.images);
arrayList.add(a);
arrayList.add(b);
File file = new File("output.mp4");
SeekableByteChannel out = null;
try {
out = (SeekableByteChannel) NIOUtils.writableFileChannel(String.valueOf(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.e("msg",e.toString());
}
try {
encoder = new AndroidSequenceEncoder((org.jcodec.common.io.SeekableByteChannel) out, Rational.R(25,1));
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(this, "in for loop", Toast.LENGTH_SHORT).show();
for(int i=0 ;i<arrayList.size() ; i++){
try {
encoder.encodeImage(arrayList.get(i));
} catch (IOException e) {
e.printStackTrace();
}
}
Toast.makeText(this, "out of loop", Toast.LENGTH_SHORT).show();
try {
encoder.finish();
} catch (IOException e) {
e.printStackTrace();
}
NIOUtils.closeQuietly(out);
}
}
}
希望我能很快得到回复。 谢谢。
最佳答案
File file = new File("output.mp4");
这并没有指向任何有用的地方。始终使用一种方法来导出要写入的根位置。
例如,您可以将其更改为:
File file = new File(getFilesDir(), "output.mp4");
或:
File file = new File(getExternalFilesDir(null), "output.mp4");
关于android - java.io.FileNotFoundException : output. mp4(只读文件系统),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46364126/