在播放本地视频android时出错



我在类似的路径上有文件

"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(); 
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>

使用以上代码并尝试。播放视频的简单代码。MAke确实添加了SD卡读写<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> 的权限

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();
           }   
     }

最新更新