我的媒体录制器录制视频后录制我正在预览我的视频(很好)。 现在将此视频上传到我当地的http服务器上。 并最终从服务器获取此视频,但它显示无法播放视频。
任何有关实际错误的建议...... Thanx寻求帮助。
MediaRecorder
this.mediaRecorder = new MediaRecorder();
this.mediaRecorder.setCamera(this.camera);
camera.unlock();
this.mediaRecorder.setCamera(camera);
this.mediaRecorder.setOrientationHint(90);
this.mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
this.mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
this.mediaRecorder.setProfile(camcorderProfile_HQ);
this.mediaRecorder.setOutputFile(this.initFile().getAbsolutePath());
this.mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
this.mediaRecorder.setMaxFileSize(5000000);
this.mediaRecorder.setPreviewDisplay(this.cameraPreview.getHolder().getSurface());
try {
this.mediaRecorder.prepare();
// start the actual recording
// throws IllegalStateException if not prepared
this.mediaRecorder.start();
Toast.makeText(this, R.string.recording, Toast.LENGTH_SHORT).show();
// enable the stop button by indicating that we are recording
this.toggleButtons(true);
} catch (Exception e) {
Log.wtf(TAG, "Failed to prepare MediaRecorder", e);
Toast.makeText(this, R.string.cannot_record, Toast.LENGTH_SHORT).show();
this.releaseMediaRecorder();
}
视频观看
Uri uri = Uri.parse("/data/data/com.example.mediarecorder/files/"+ messageList.get(position)); //do not add any extension
video.setVideoURI(uri);
video.requestFocus();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
video.setKeepScreenOn(true);
System.out.println(uri + " "+ uri.getEncodedAuthority()+ " "+ uri.decode(data_type) + " "+ uri.getUserInfo() + " "+ uri.describeContents());
video.start();
答案 0 :(得分:4)
您无法通过videoview播放内部存储中的视频,因为该文件没有全局读取权限。您必须使用surfaceView和媒体播放器类创建自定义视频播放器。然后你必须创建你需要播放的文件的文件描述符,并将其传递给mediaPlayer.setDataSource():
FileInputStream inputStream = new FileInputStream(videoPath);
//assume videoPath = getFilesDir().getAbsolutePath()) + File.separator + "Video.mp4"
mp.setDataSource(inputStream.getFD());
mp.prepareAsync();
try {
mp.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mplayer) {
if (mp != null) {
mp.start();
}
}
});