使用视频查看器的最佳方式。并播放视频

时间:2011-08-31 00:04:40

标签: android android-videoview

有没有办法播放存储在原始文件中的视频,而不使用uri。如果不是我如何正确设置uri。假设我有一个名为movie的文件,我想用视频查看器播放它。我该怎么办?我还必须将数据写入SD卡。或者我可以从原始播放它。

为什么我不能这样做

uri uri.parse("android.resources://"+this.getApplicationContext().getPackageName()+movie);

这就是我现在所拥有的,如果你可以指出错误给我,所以我知道,我不会再有这个问题了

          VideoView videoview = (VideoView) findViewById(R.id.videoView1);
          videoview.setKeepScreenOn(true);
          videoview.setVideoPath("android.raw://com.example.movievp8");
          MediaController controller = new MediaController(videoview.getContext()); 
          videoview.setMediaController(controller);           
          videoview.start();
          videoview.requestFocus();      

1 个答案:

答案 0 :(得分:0)

这对我有用:

  videoResource = R.raw.some_video;
  String uri = String.format("android.resource://%s/%d", context.getPackageName(), videoResource);
  animationCanvas = (VideoView) ui.findViewById(R.id.animation_canvas);
  animationCanvas.setVisibility(View.VISIBLE);
  animationCanvas.setVideoURI(Uri.parse(uri));
  animationCanvas.setOnCompletionListener(this);
  animationCanvas.setOnPreparedListener(new OnPreparedListener() {
      public void onPrepared(MediaPlayer mp) {
          animationCanvas.start();

      }
  });
相关问题