[英]How to play my recorded video on my own media player using the URI of the recorded video in android?
My app record video by using phone camera and I add the URI of the video in a String type ArrayList, Here is my code of adding video URI in the list. 我的应用程序使用手机摄像头录制视频,然后将视频的URI添加到String类型ArrayList中,这是我在列表中添加视频URI的代码。
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
if (requestCode == REQUEST_VIDEO_CAPTURED)
{
uriVideo = data.getData();
cameraVideoList.add(uriVideo.toString());
adapter.notifyDataSetChanged();
}
}
}
I am passing the video URI (content://media/external/video/media/60)
to my Media Player to play the recorded video but the media player does not play the video. 我正在将视频URI (content://media/external/video/media/60)
传递给我的媒体播放器以播放录制的视频,但媒体播放器无法播放该视频。 Here is the code of my media player. 这是我的媒体播放器的代码。
public class PlayVideoCamera extends Activity
{
private static ProgressDialog progressDialog;
VideoView videoView ;
String videoURI =null;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // Fixed
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // orientation
setContentView(R.layout.videoview);
videoView = (VideoView) findViewById(R.id.video_view);
Bundle bundle = getIntent().getExtras();
videoURI= bundle.getString("VideoURI");
progressDialog = ProgressDialog.show(PlayVideoCamera.this, "", "Loading...",true);
progressDialog.setCancelable(true);
PlayVideo();
// setContentView(videoView);
}
private void PlayVideo()
{
try
{
getWindow().setFormat(PixelFormat.TRANSLUCENT);
MediaController mediaController = new MediaController(PlayVideoCamera.this);
mediaController.setAnchorView(videoView);
// Toast.makeText(getApplicationContext(), "Video:\t"+videoIndex, Toast.LENGTH_LONG).show();
Uri video = Uri.parse(videoURI);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
progressDialog.dismiss();
videoView.start();
}
});
}
catch(Exception e)
{
progressDialog.dismiss();
System.out.println("Video Play Error :"+e.toString());
finish();
}
}
}
Please help me to play my recorded video, I will be very thankful to you. 请帮助我播放录制的视频,非常感谢您。
URI contains protocol name not "content" keyword. URI包含协议名称,而不是“ content”关键字。 You can try file:// or you stream over internet http:// 您可以尝试file://或通过Internet http://流式传输
Try this URI file:///media/external/video/media/60 试试这个URI文件:/// media / external / video / media / 60
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.