Reputation: 2248
I am using the 0.4.2 version of the jar in my project to record video an upload it. The file name returned from SimpleCameraHost.getVideoFileName() is wrong on my Nexus 4.
It looks like the file name is time stamped and I have a file Video_20131113_223704.mp4 on the device but the method returned Video_20131113_223708.mp4 off by 4 seconds?
Is there something I should be doing to get a proper filename?
P.S. I would add a cwac-camera tag if I had enough rep...
Upvotes: 2
Views: 317
Reputation: 3016
I had the same issue with photos but basically I also thought that getPhotoPath would return the path of the photo I had just taken.
So I read carefully CommonsWare answer, especially the part where he explains how getVideoPath() works.
That's because getVideoPath() is designed to be called by CameraView, to generate the >filename to be used for the video. getVideoFileName(), in turn, is used by getVideoPath(). >This has to be done before the video starts recording.
My understanding is that getVideoPath() is meant to be used by the system rather than by the developper. getVideoPath() calls getVideoFilename() and getVideoDirectory() to build the video path which will later be used by the system to save the video.
That being said, what we need to do (like CommonsWare already said), is to tell the system what path we want our file to be saved at. And we do this by overriding either getVideoFilename(), getVideoDirectory() or getVideoPath().
And once we control that, we can always call getVideoPath() once the video is saved, just to be sure we have the right path.
So since I was happy with the default directory, I just overrode getPhotoFilename() like this :
public class MyCameraHost extends SimpleCameraHost {
private String photoName;
private String extension = ".png";
public MyCameraHost(Context _ctxt) {
super(_ctxt);
// TODO Auto-generated constructor stub
}
@Override
protected String getPhotoFilename() {
// TODO Auto-generated method stub
return this.photoName + this.extension;
}
public void setPhotoName (String name){
this.photoName = name;
}
}
And in my camera activity, my takePhoto() method looks like this :
private void takePicture() {
CameraFragment f = (CameraFragment) getFragmentManager().findFragmentByTag(TAG_CAMERA_FRAGMENT);
if (f != null && f.isVisible()) {
cameraHost.setPhotoName("test");
f.takePicture();
pictureFile = cameraHost.getPhotoPath();
}
}
Hope this helps. And thanks CommonWares for this awesome library and your answers to our questions.
Upvotes: 0
Reputation: 1006869
Starting and stopping record in your CameraFrament class created a file ending with _223704.mp4 on my device
That's because getVideoPath()
is designed to be called by CameraView
, to generate the filename to be used for the video. getVideoFileName()
, in turn, is used by getVideoPath()
. This has to be done before the video starts recording.
Then calling into the SimpleCameraHost method getVideoFileName() in my subclass returned a videoFileName ending with _223708.mp4 so when I tried to upload the file returned from your method it failed becuase that file doesn't exist.
You don't call getVideoFileName()
, you implement it. The expectation is that if you are using the stock implementation, you do not need the filename in your own code. If you need the filename, override getVideoFileName()
(and/or related methods, like getVideoPath()
), return what you want (which could very well be whatever the superclass returns), and hold onto the result for later use.
Upvotes: 2