Добрый день, в своем приложении я снимаю видео на мобильную камеру, затем запускаю это видео, спасибо
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
{
Surface s = new Surface(surface);
try
{
mp = new MediaPlayer();
mp.setDataSource(getVideoFilePath());
mp.setSurface(s);
mp.prepare();
mp.setOnBufferingUpdateListener(this);
mp.setOnCompletionListener(this);
mp.setOnPreparedListener(this);
mp.setOnVideoSizeChangedListener(this);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
setPreviewSize(true);
mp.start();
}
catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Я реализовал метод, который делает снимок экрана и сохраняет его в галерее,
public void getBitmap(TextureView vv)
{
String mPath = getAndroidImageFolder().getAbsolutePath() + "/" + new SimpleDateFormat("yyyyMM_dd-HHmmss").format(new Date()) + "cameraRecorder.png";
Toast.makeText(getApplicationContext(), "Capturing Screenshot: " + mPath, Toast.LENGTH_SHORT).show();
Bitmap bm = vv.getBitmap();
if(bm == null)
Log.e(TAG,"bitmap is null");
OutputStream fout = null;
File imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bm.compress(Bitmap.CompressFormat.PNG, 90, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
Log.e(TAG, "FileNotFoundException");
e.printStackTrace();
} catch (IOException e) {
Log.e(TAG, "IOException");
e.printStackTrace();
}
}
Но скриншот не появляется в галерее и выбивает ошибку.
Вот что выдает в Logcat
E/TextureViewActivity: FileNotFoundException
11-14 15:25:09.961 4143-4143/com. W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/201811_14-152509cameraRecorder.png: open failed: ENOENT (No such file or directory)
11-14 15:25:09.971 4143-4143/com. W/System.err: at libcore.io.IoBridge.open(IoBridge.java:452)
11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
11-14 15:25:09.971 4143-4143/com. W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
11-14 15:25:09.971 4143-4143/com. W/System.err: at com.
camera.VideoProcessor.getBitmap(VideoProcessor.java:245)
11-14 15:25:09.971 4143-4143/com. W/System.err: at com.camera.VideoProcessor.onClick(VideoProcessor.java:369)
Вот на какую часть кода выбивает ошибку
at com.camera.VideoProcessor.getBitmap(VideoProcessor.java:247) -> fout = new FileOutputStream(imageFile);
Буду очень признателен за вашу помощь)