Tengo una base de datos En MongoDB (y GridFS) en la cual tengo archivos multimedia (Específicamente vídeos .mp4) y estoy tratando de acceder a estos vídeo, la conexión no genere ningún error y cuando quiero extraer imágenes desde la base de datos, me la muestra sin ningún problema; pero a la hora de Extraer los vídeos, La base de datos me devuelve el archivo de vídeo en un ByteArray y este a su vez lo estoy convirtiendo en un archivo temporal para obtenerlo en el videoView de la siguiente forma:
En esta parte estoy trayendo los bytes desde la base de datos:
public byte[] video () {
GridFSBucket gridFSBucket = GridFSBuckets.create(connection.getDatabaseDB(), "test");
gridFSBucket.find().forEach(
(Block<GridFSFile>) gridFSFile -> {
if ( gridFSFile.getFilename().equalsIgnoreCase("video2")) {
setId(gridFSFile.getObjectId());
}
}
);
//gridFSBucket.find().forEach();
GridFSDownloadStream downloadStream = gridFSBucket.openDownloadStream(id);
int length = (int) downloadStream.getGridFSFile().getLength();
byte[] bytesVideo = new byte[length];
downloadStream.read(bytesVideo);
downloadStream.close();
//connection.closeClient();
return bytesVideo;
}
En la siguiente parte estoy obteniendo este byte Array y lo estoy convirtiendo a un archivo .mp4
public void procesoVid () {
try {
byte [] bitVid = databaseM.video();
file = File.createTempFile("video", ".mp4", getCacheDir());
if (!file.exists()) {
file.mkdir();
}
file.setExecutable(true);
file.setReadable(true);
file.setWritable(true);
file.deleteOnExit();
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(bitVid);
fileOutputStream.close();
mostrarVideo(file);
} catch (Exception ex3) {
Toast.makeText(this, "Error 3: " + ex3.getMessage(), Toast.LENGTH_LONG).show();
}
}
Metodo mostrar video:
public void mostrarVideo (File fi) {
mdc = new MediaController(PruebaMDB.this);
mdc.setAnchorView(video);
mdc.setMediaPlayer(video);
video.setMediaController(mdc);
video.setVideoURI( Uri.parse(fi.getAbsolutePath()) );
video.requestFocus();
video.start();
}
También intente convertir el vídeo con FFMPEG pero realmente no sé como funciona ya que tampoco me funciona ya que me aparece que tiene un error con la posicion del Moov. El error original que me aparece es este:
E/MediaPlayer: error (1, -2147483648)
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 4
D/EGL_emulation: eglMakeCurrent: 0x985916c0: ver 2 0 (tinfo 0x98589380)
E/MediaPlayer: Error (1,-2147483648)
D/VideoView: Error: 1,-2147483648
Ojala me puedan ayudar, gracia.