Android videoview黑屏只有视频输出

时间:2015-12-10 04:03:55

标签: android android-sdcard android-videoview mediacontroller

从手机播放视频时遇到问题。输出是黑屏,没有任何反应。我该怎么办?

public class Videoview extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.plant_info);
    VideoView videoView =(VideoView) findViewById(R.id.video_view);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/raw/kitkat.mp4");
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    videoView.start();

1 个答案:

答案 0 :(得分:0)

使用以下代码

VideoView videoView = (VideoView) findViewById(R.id.video_view);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        int resID = getResources().getIdentifier("kitkat", "raw", this.getPackageName());
        Uri video1 = Uri.parse("android.resource://" + this.getPackageName() + "/" + resID); //do not add any extension
        videoView.setMediaController(null);
        videoView.stopPlayback();
        videoView.setVideoURI(video1);
        // Log.i("video1..", ".." + video1 + ".." + resID);
        videoView.requestFocus();
        videoView.start();