2

我的应用程序使用手机摄像头录制视频,并将视频的 URI 添加到字符串类型的 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();
                }
            }
        }

我将视频 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();
          } 

    }

}

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

4

1 回答 1

1

URI 包含协议名称而不是“内容”关键字。您可以尝试 file:// 或通过 Internet http:// 流式传输

试试这个 URI file:///media/external/video/media/60

于 2013-02-18T12:12:15.990 回答