Reputation: 412
I am using this library for a video sharing application project and I am using the CameraDemo_layout and I am setting the com.commonsware.cwac.camera.CameraView dimensions to 320dip in both, height and width. However, the recorded video seems to have the recording with the dimensions of the phone screen which makes it look so wrong. Would you please walk me through the process of setting the video recording to follow the dimensions of the camera viewgroup layout. Thank you.
My Activity:
public class RecordingActivity extends Activity implements
CameraHostProvider { private DemoCameraFragment current=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recording);
current=new DemoCameraFragment();
getFragmentManager().beginTransaction()
.replace(R.id.container, current).commit();
}
@Override
public CameraHost getCameraHost() {
return(new SimpleCameraHost(this));
}
My Fragment:
public class DemoCameraFragment extends CameraFragment {
android.hardware.Camera camera;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View content=inflater.inflate(R.layout.camera, container, false);
CameraView cameraView=(CameraView)content.findViewById(R.id.camera);
Log.d("daba", "the cameraview attrs: " + cameraView.getHeight() + " -- " + cameraView.getWidth());
setCameraView(cameraView);
// SimpleCameraHost.Builder builder = new SimpleCameraHost.Builder(getActivity());
// builder.useFullBleedPreview(false);
//
// setHost(builder.build());
final ImageButton record = (ImageButton) content.findViewById(R.id.record);
final ImageButton next = (ImageButton) content.findViewById(R.id.next);
next.setEnabled(false);
record.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(record.getTag().toString().equals("Hi!")){
try {
record();
record.setTag("By!");
record.setBackgroundColor(Color.DKGRAY);
next.setEnabled(true);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else{
try {
stopRecording();
record.setTag("Hi!");
record.setBackgroundColor(Color.TRANSPARENT);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(isRecording())
Toast.makeText(getActivity(), "Finish recording first", Toast.LENGTH_SHORT).show();
else{
Intent i = new Intent(getActivity(), VideoSetData.class);
getActivity().startActivity(i);
}
}
});
if(isRecording()){
}
return(content);
}
}
My Camera.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.commonsware.cwac.camera.CameraView
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/cancel" />
<ImageButton
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/right" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/record"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/record"
android:tag="Hi!" >
</ImageButton>
</LinearLayout>
Upvotes: 0
Views: 799
Reputation: 1007614
However, the recorded video seems to have the recording with the dimensions of the phone screen which makes it look so wrong
The resolution of the recording should have nothing to do with the dimensions of the CameraView
. The resolution of the recording should come from your configuration of the MediaRecorder
using setProfile()
.
setProfile()
is used in the CameraHost
in configureRecorderProfile()
. The SimpleCameraHost
uses its own algorithm for choosing a profile; you will need to subclass SimpleCameraHost
and override configureRecorderProfile()
to use a different algorithm for choosing a profile.
Upvotes: 1