Java 在播放本地视频时出错

Java 在播放本地视频时出错,java,android,android-mediaplayer,Java,Android,Android Mediaplayer,我的文件路径如下 ”file:///storage/emulated/0/Android/data/com.testcompany.tesapp/files/recs/1234-7896-9076.mp4“ videoView.setVideoURI(Uri.parse(“file:///storage/emulated/0/Android/data/com.testcompany.tesapp/files/recs/1234-7896-9076.mp4(“”) 播放开始了,但我遇到了这样的错误

我的文件路径如下

”file:///storage/emulated/0/Android/data/com.testcompany.tesapp/files/recs/1234-7896-9076.mp4“ videoView.setVideoURI(Uri.parse(“file:///storage/emulated/0/Android/data/com.testcompany.tesapp/files/recs/1234-7896-9076.mp4(“”)

播放开始了,但我遇到了这样的错误

11-10 14:12:30.909: E/MediaPlayer(1022): Error (1,-2147483648) 

我搜索了这个错误,它说这是未知的MediaPlayer错误,所以如何避免它。

使用此代码从存储器播放视频

Uri vidFile = Uri.parse(
    Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/"+"xyz.mp4");
    VideoView videoView = (VideoView) findViewById(R.id.videoView);
    videoView.setVideoURI(vidFile);
    videoView.setMediaController(new MediaController(MainActivity.this));
    videoView.setVisibility(1);
    videoView.bringToFront();
    videoView.requestFocus();
    videoView.start(); 
}



使用上面的代码并尝试。简单的代码可以播放视频。确保添加了SD卡读写权限

检查viedo是否在这里。您可能正在从android资源播放viedo
package com.AnVideoView;

import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class AnVideoView extends Activity {

 String SrcPath = "/sdcard/Video/Android in Spaaaaaace!_low.mp4";

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
       myVideoView.setVideoPath(SrcPath);
       myVideoView.setMediaController(new MediaController(this));
       myVideoView.requestFocus();
       myVideoView.start();
   }
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<LinearLayout
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   >
<VideoView
   android:id="@+id/myvideoview"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
</LinearLayout>
</LinearLayout>
private void startVideo() {
      try{
          viv_share_video = (VideoView)findViewById(R.id.viv_share_video);

          progressDialog = ProgressDialog.show(PlayVideo.this, "", "Buffering video...", true);
          progressDialog.setCancelable(true);
          getWindow().setFormat(PixelFormat.TRANSLUCENT);
          MediaController mediaController = new MediaController(PlayVideo.this);
          mediaController.setAnchorView(viv_share_video);           

           Uri video = Uri.parse(record_video_path);             
           viv_share_video.setMediaController(mediaController);
           viv_share_video.setVideoURI(video);
           viv_share_video.requestFocus();              
           viv_share_video.setOnPreparedListener(new OnPreparedListener()
           {

               public void onPrepared(MediaPlayer mp)
               {                  
                   progressDialog.dismiss();     
                   viv_share_video.start();
               }
           });           
         }catch(Exception e){
                    progressDialog.dismiss();
                    goBack();
           }   

     }