我知道这是一个古老的问题,但我找不到正确的答案。我想通过彩信分享我的视频,但我继续收到此错误“无法附加。文件不支持”。
以下是我的Code First是我的录音课,第二个是视频播放器:
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;
}
}
}
这是我的视频播放器课程
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。路径没问题,因为它适用于电子邮件。 编辑#2:附上完整的代码请检查是否在正确传递视频时出现问题。
答案 0 :(得分: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"));
答案 1 :(得分: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"));
让我知道你的状态。