简体   繁体   English

videoView Android无法播放视频

[英]Video can not be played by videoView Android

I am developing video player app. 我正在开发视频播放器应用。 I want this app to be appear as option on selecting video from sdcard, album or any folder of the phone . 我希望此应用程序在从SD卡,相册或手机的任何文件夹中选择视频时显示为选项。 When i select my video player to play video, it takes to app but video is not playing. 当我选择我的视频播放器播放视频时,它需要应用程序,但视频不播放。 I have given permission to read and write external storage in manifest.Below is my code : 我已经允许在manifest中读写外部存储。这是我的代码:

 Intent in =getIntent();
 file_path = in.getData().getPath();
 System.out.println("file path from sdcard:"+file_path);
  videoView =(VideoView)findViewById(R.id.video);

   MediaController mediaController= new MediaController(this);
    mediaController.setAnchorView(videoView);        
     Uri uri=Uri.parse(file_path);        
     videoView.setVideoURI(uri);        
     videoView.requestFocus();
         videoView.start();

ERROR : 错误:

 10-19 10:39:40.917: I/System.out(20430): file path from sdcard:/external/video/media/24363
 10-19 10:39:40.987: E/MediaPlayer(20430): Uri is  <URL suppressed>
 10-19 10:39:40.997: E/MediaPlayer(20430): error (1, -2147483648)
 10-19 10:39:41.017: E/MediaPlayer(20430): Error (1,-2147483648)
 10-19 10:39:41.017: D/VideoView(20430): Error: 1,-2147483648

EDIT: testing phone : Android 4.1 with 32Gb inbuilt memory and does not have Sdcard. 编辑:测试手机:Android 4.1与32Gb内置内存,没有Sdcard。

Answer for this is here 答案就在这里

 public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Video.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

I had this same problem, went down many different paths to fix it, and what finally ended up working was the following code block: 我有同样的问题,沿着许多不同的路径修复它,最终最终工作的是以下代码块:

/* inside onCreate */
VideoView videoView = (VideoView)findViewById(R.id.loginVideoBackground);
videoView.setVideoURI(Uri.parse("android.resource://" + this.getPackageName() + "/raw/lights"));
videoView.start();

I had previously tried: 我曾经尝试过:

  • Extending SurfaceView 扩展SurfaceView
  • using the answer given by @brinda above (which was resulting in a NullPointerException ) 使用@brinda上面给出的答案(导致NullPointerException
  • and various other permutations of StackOverflow answers 以及StackOverflow答案的各种其他排列

....sometimes simpler is better ....有时候更简单更好

/external/video/media/24363 is not correct, please check. /external/video/media/24363不正确,请检查。 local path must be visit..eg /sdcard/video/media/.. 本地路径必须访问..eg / sdcard / video / media / ..

videoView.setVideoPath("http://www.ebookfrenzy.com/android_book/movie.mp4");        MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.start();

To be honest, I've experienced similar problems in the past and for each account, what I've ultimately found to be the best solution was to extend SurfaceView, directly. 说实话,我在过去和每个帐户都经历过类似的问题,我最终发现最好的解决方案是直接扩展SurfaceView。 There is a surprisingly small amount of code to write and can easily (relatively speaking) be tailored efficiently to your requirements. 编写的代码数量惊人,并且可以轻松(相对而言)根据您的要求进行有效定制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM