Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to connect surface view with media recorder inside the compose mail function
    primarykey
    data
    text
    <p>I have created a compose mail function inside that I designed a surface view option to record a video using mobile camera but it force closes the app. But it works in separate apps. Why I cant integrate both in one app?</p> <p>Here's my code</p> <p>main.xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:weightSum="1"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /&gt; &lt;RelativeLayout android:id="@+id/relativeLayout1" android:layout_weight="1.04" android:layout_height="wrap_content" android:layout_width="match_parent"&gt; &lt;TextView android:layout_width="wrap_content" android:textAppearance="? android:attr/textAppearanceLarge" android:id="@+id/textTo" android:layout_height="wrap_content" android:text="To : "&gt;&lt;/TextView&gt; &lt;EditText android:layout_alignParentLeft="true" android:layout_width="fill_parent" android:layout_below="@+id/textTo" android:inputType="textEmailAddress" android:layout_height="wrap_content" android:id="@+id/editTextTo"&gt; &lt;requestFocus&gt;&lt;/requestFocus&gt; &lt;/EditText&gt; &lt;TextView android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_below="@+id/editTextTo" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/textViewSubject" android:layout_height="wrap_content" android:text="Subject : "&gt;&lt;/TextView&gt; &lt;EditText android:layout_alignParentLeft="true" android:layout_width="fill_parent" android:layout_below="@+id/textViewSubject" android:layout_height="wrap_content" android:id="@+id/editTextSubject"&gt;&lt;/EditText&gt; &lt;TextView android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_below="@+id/editTextSubject" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/textViewMessage" android:layout_height="wrap_content" android:text="Message : "&gt;&lt;/TextView&gt; &lt;EditText android:layout_alignParentLeft="true" android:layout_width="160dp" android:layout_below="@+id/textViewMessage" android:inputType="textMultiLine" android:layout_height="225dp" android:id="@+id/editTextMessage" android:gravity="top" android:lines="5"&gt;&lt;/EditText&gt; &lt;SurfaceView android:layout_height="225dp" android:id="@+id/videoview" android:layout_toRightOf="@+id/editTextMessage" android:layout_width="160dp" android:layout_alignBottom="@+id/editTextMessage" android:layout_alignTop="@+id/editTextMessage" android:layout_alignParentRight="false"&gt; &lt;/SurfaceView&gt; &lt;Button android:layout_width="75dp" android:text="Send" android:layout_height="50dp" android:id="@+id/buttonSend" android:layout_alignParentBottom="true" android:layout_alignLeft="@+id/videoview" android:layout_marginLeft="18dp"&gt;&lt;/Button&gt; &lt;Button android:layout_width="75dp" android:text="Rec" android:layout_height="50dp" android:id="@+id/mybutton" android:layout_alignParentBottom="true" android:layout_alignRight="@+id/textViewSubject"&gt;&lt;/Button&gt; </code></pre> <p></p> <p></p> <p>manifest file:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.SampleRecord" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-sdk android:minSdkVersion="8" /&gt; &lt;uses-permission android:name="android.permission.RECORD_AUDIO"/&gt; &lt;uses-permission android:name="android.permission.CAMERA"/&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt; &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".SampleRecordActivity" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>SampleRecordActivity.java</p> <pre><code> public class SampleRecordActivity extends Activity implements SurfaceHolder.Callback { Button buttonSend,btnrec; EditText textTo; EditText textSubject; EditText textMessage; Button myButton; MediaRecorder mediaRecorder; SurfaceHolder surfaceHolder; boolean recording; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); recording = false; mediaRecorder = new MediaRecorder(); initMediaRecorder(); SurfaceView myVideoView = (SurfaceView)findViewById(R.id.videoview); surfaceHolder = myVideoView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); myButton = (Button)findViewById(R.id.mybutton); myButton.setOnClickListener(myButtonOnClickListener); buttonSend = (Button) findViewById(R.id.buttonSend); textTo = (EditText) findViewById(R.id.editTextTo); textSubject = (EditText) findViewById(R.id.editTextSubject); textMessage = (EditText) findViewById(R.id.editTextMessage); buttonSend.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String to = textTo.getText().toString(); String subject = textSubject.getText().toString(); String message = textMessage.getText().toString(); Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to}); email.putExtra(Intent.EXTRA_CC, new String[]{ to}); email.putExtra(Intent.EXTRA_BCC, new String[]{to}); email.putExtra(Intent.EXTRA_SUBJECT, subject); email.putExtra(Intent.EXTRA_TEXT, message); //need this to prompts email client only email.setType("message/rfc822"); startActivity(Intent.createChooser(email, "Choose an Email client :")); } }); } private Button.OnClickListener myButtonOnClickListener= new Button.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub if(recording) { mediaRecorder.stop(); mediaRecorder.release(); finish(); } else { mediaRecorder.start(); recording = true; myButton.setText("STOP"); } } }; @Override public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void surfaceCreated(SurfaceHolder arg0) { // TODO Auto-generated method stub prepareMediaRecorder(); } @Override public void surfaceDestroyed(SurfaceHolder arg0) { // TODO Auto-generated method stub } private void initMediaRecorder(){ mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); mediaRecorder.setProfile(camcorderProfile_HQ); mediaRecorder.setOutputFile("/sdcard/myvideo.mp4"); mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec. mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M } private void prepareMediaRecorder(){ mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface()); try { mediaRecorder.prepare(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload