I created a custom camera capturing videos. I want to send the video I just capture to a new Activity containing a videoView, via an intent, in order to preview the video before to save it (on my mobile or on a server).
The "PreviewVideoActivity" opens after the recording BUT I don't see anything (only a black or white screen). I don't know if it's because my video is not ready to be displayed or if something is wrong in my intent code... Please heeeelp :)
Here is my code :
In the "TakeVideoActivity" where my custom camera is coded, I call processVideo(videoFile); when I stop recording and here is its code :
public void processVideo(File videoFile) {
//File videoFile = getOutputMediaFile();
if (videoFile == null) {
return;
}
try {
sendToPreviewVideoActivity(videoFile, mContext);
} catch (Exception e) {
e.printStackTrace();
}
}
//called whenever a pic is shot or video is recorded
public void sendToPreviewVideoActivity(File videoFile, Context mContext) {
System.out.println("sendToPreviewVideoActivity called");
Uri filePath = Uri.fromFile(videoFile);
String value= videoFile.getAbsolutePath();
Intent i = new Intent(this, PreviewVideoActivity.class);
i.putExtra("file_path", filePath.toString());
i.putExtra("uploadFilePath", value);
startActivity(i);
}
And here is the "PreviewVideoActivity" :
public class PreviewVideoActivity extends ActionBarActivity {
private VideoView mVideoView;
private String filePath = null;
private Uri mVideoUri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview_video);
mVideoView = (VideoView) findViewById(R.id.video_view);
// Receiving the data from previous activity
Intent i = getIntent();
// image or video path that is captured in previous activity
filePath = i.getStringExtra("filePath");
putPreviewVideo(i);
}
private void putPreviewVideo(Intent intent) {
mVideoUri = intent.getData();
mVideoView.setVideoURI(mVideoUri);
//mVideoView.setVisibility(View.VISIBLE);
mVideoView.setZOrderOnTop(true);
mVideoView.setBackgroundColor(Color.WHITE); // Your color.
mVideoView.start();
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mVideoView.setBackgroundColor(Color.TRANSPARENT);
}
});
//mVideoView.start();
}
}
Thanks !
Aucun commentaire:
Enregistrer un commentaire