1

古い質問であることは知っていますが、正しい答えが見つかりません。MMS 経由でビデオを共有したいのですが、「添付できません。ファイルがサポートされていません」というエラーが表示され続けます。

以下は私のコードです。最初は私のレコーディングクラスで、2番目はビデオプレーヤーです:

public class VideoComponent extends Activity  {
    private SurfaceHolder surfaceHolder;
    private SurfaceView surfaceView;
    public MediaRecorder mrec = new MediaRecorder();
    private Button startRecording = null;
    private Button stopRecording = null;
    private Button play = null;
    private Button gallery = null;
    int BytesPerElement = 2;

    File video;
    private Camera mCamera;
    File audiofile = null;
    boolean recording=false;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main1);

        startRecording = (Button)findViewById(R.id.buttonstart);
        stopRecording = (Button)findViewById(R.id.share);
        play=(Button)findViewById(R.id.play);
        gallery= (Button)findViewById(R.id.gallery);


        mCamera = Camera.open();
        surfaceView = (SurfaceView) findViewById(R.id.surface_camera);


        surfaceHolder = surfaceView.getHolder();


        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        startRecording.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    if(recording==false)
                        startRecording();

                } catch (IOException e) {
                    Log.i("test" , "Video Not starting");

                }

            }
        });
        stopRecording.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {


                    recording=false;
                    stopRecording();

            }
        });
        play.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i= new Intent(getApplicationContext(),VideoPlayer.class);
                i.putExtra("URI", audiofile.getAbsolutePath());
                startActivity(i);
            }
        });

        gallery.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i= new Intent(getApplicationContext(),Gallery.class);
                startActivity(i);
            }
        });


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
          Log.i("Test" , "Menu thing");
        menu.add(0, 0, 0, "StartRecording");
        menu.add(0, 1, 0, "StopRecording");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
        case 0:
            try {
                  Log.i("Test" , "Start Recording");
                startRecording();
            } catch (Exception e) {
                String message = e.getMessage();
                Log.i("Self", "Problem Start"+message);
                mrec.release();
            }
            break;

        case 1: //GoToAllNotes
            mrec.stop();
            mrec.release();
            mrec = null;
            break;

        default:
            break;
        }
        return super.onOptionsItemSelected(item);
    }

    public void startRecording() throws IOException 
    {
        recording=true;
        String path= Environment.getExternalStorageDirectory().toString();
        File sampleDir = new File(path+"/DCIM/Camera");
        sampleDir.mkdir();


         Log.i("Setting Path", sampleDir.toString());

            try {
              audiofile = File.createTempFile("Video", ".3gp", sampleDir);
            } catch (IOException e) {

              return;}
            int minBufferSize = AudioRecord.getMinBufferSize(8000, 
                 AudioFormat .CHANNEL_IN_MONO, 
                 AudioFormat.ENCODING_PCM_16BIT);
        mrec = new MediaRecorder();  // Works well

        mCamera.unlock();
        mrec.setCamera(mCamera);

        mrec.setPreviewDisplay(surfaceHolder.getSurface());
        mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mrec.setAudioSource(MediaRecorder.AudioSource.MIC);
        mrec.setMaxDuration(60000);
        mrec.setAudioSamplingRate(16000);
        mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
        mrec.setPreviewDisplay( surfaceHolder.getSurface());
        mrec.setOutputFile(audiofile.getAbsolutePath()); 
        mrec.prepare();
        mrec.start();


    }

    protected void stopRecording() {
        mrec.stop();
        mrec.release();
        mCamera.lock();
        mCamera.release();
        Log.i("testing","going to call Destroyer");
        //surfaceDestroyed(surfaceHolder);

        //mCamera.stopPreview();


         //finish();
    }

   private void releaseMediaRecorder(){
       Log.i("testing","re;ease Media record"); 
       if (mrec != null) {
            mrec.reset();   // clear recorder configuration
            mrec.release(); // release the recorder object
            mrec = null;
            mCamera.lock();           // lock camera for later use
        }
    }

    private void releaseCamera(){
           Log.i("testing","re;ease Camera");
        if (mCamera != null){
            mCamera.release();        // release the camera for other applications
            mCamera = null;
        }
    }
}

これは私の Video Player クラスです

public class VideoPlayer extends Activity {
VideoView videoView;
Button mms=null;
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    //Create a VideoView widget in the layout file
    //use setContentView method to set content of the activity to the layout file which contains videoView
    this.setContentView(R.layout.video);
    final Intent i= getIntent();
    final String uri=i.getStringExtra("URI");
    Log.i("URI","Path is"+Uri.parse(uri));

    mms=(Button)findViewById(R.id.mms);

    videoView = (VideoView)this.findViewById(R.id.videoView1);

    //add controls to a MediaPlayer like play, pause.
    MediaController mc = new MediaController(this);
    videoView.setMediaController(mc);

    //Set the path of Video or URI
    videoView.setVideoURI(Uri.parse(uri));

  //Set the focus
    videoView.requestFocus();
    videoView.start();


    mms.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_SEND);
             i.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
            i.putExtra(Intent.EXTRA_STREAM,Uri.parse(uri));
            i.setType("video/*");
            startActivity(i);
        }
    });
}
}

マニフェスト ファイル

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.videoplayer"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="17" />

 <uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera" />
<application android:icon="@drawable/icon"
     android:label="@string/app_name"
      android:debuggable="true">
    <activity android:name=".VideoComponent"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     <activity android:name=".VideoPlayer"
              android:label="@string/app_name">
        <intent-filter>
           <action android:name="android.intent.action.SEND" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:mimeType="*/*"  />
        </intent-filter>
    </activity>
    <activity android:name=".VideoRecorder"
              android:label="@string/app_name">

    </activity>
    <activity android:name=".Gallery"
              android:label="@string/app_name">
    </activity>
</application>
</manifest>

編集: ファイル形式は .3gp です。電子メールで機能しているため、パスに問題はありません。EDIT # 2: 完全なコードが添付されています。ビデオの uri を正しく渡す際に問題がないか確認してください。

4

2 に答える 2

0

以下の意図のように試してください

            ArrayList<Uri> imageUris = new ArrayList<Uri>();
            for (int i = 0; i < checkeditem.size(); i++) {
                File file = new File(RecordService.DEFAULT_STORAGE_LOCATION,checkeditem.get(i).toString());
                Log.i("Share Media ","Sending is file is " + file.toString());
                imageUris.add(Uri.fromFile(file));
            }
            // (3) to share multiple file in URi use below code here
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
            shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,imageUris);
            shareIntent.setType("*/*");
            startActivity(Intent.createChooser(shareIntent, "Share with"));
于 2013-03-20T10:54:01.793 に答える
0

このコードを試してください:

    Intent i = new Intent(Intent.ACTION_SEND);
               i.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
               i.putExtra("Hi ", "Please find attachment"); 
               i.putExtra(Intent.EXTRA_STREAM,uri);
               i.setType("video/*");
              startActivity(Intent.createChooser(i, "Share via"));

あなたの状態を教えてください。

于 2013-03-20T11:28:52.227 に答える