如何使用Android中录制视频的URI在我自己的媒体播放器上播放我录制的视频?

时间:2013-02-18 12:03:32

标签: android camera media-player

我的应用程序使用手机摄像头记录视频,我在字符串类型ArrayList中添加视频的URI,这是我在列表中添加视频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();
                }
            }
        }

我正在将视频URI (content://media/external/video/media/60)传递给我的媒体播放器以播放录制的视频,但媒体播放器不播放视频。这是我的媒体播放器的代码。

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();
          } 

    }

}

请帮我播放录制的视频,我将非常感谢你。

1 个答案:

答案 0 :(得分:1)

URI包含协议名称而不是“content”关键字。 您可以尝试使用file://或通过互联网http://

进行流式传输

试试这个URI 文件:///媒体/外部/视频/媒体/ 60