Android:VideoView无法播放视频

时间:2014-03-19 15:05:19

标签: android android-videoview

我试图让一个基本的视频播放器工作的Android应用程序即时工作,但每当我尝试播放视频我得到一个错误说“不能播放视频”。我确定视频是支持的格式,我尝试在几种支持的格式之间进行转换,所以我认为我的代码存在问题:

public class VideoActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.video_layout);

        VideoView videoView = (VideoView)findViewById(R.id.VideoView1);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        videoView.setMediaController(mediaController);

        videoView.setVideoPath("TravelAppTopic4/res/raw/canadavid.mp4");

        videoView.start();  
    }

提前感谢任何帮助

编辑:我在虚拟设备和S3上测试到相同的结果。

2 个答案:

答案 0 :(得分:0)

public class VideoScreen extends Activity{
private MediaController controller;
Context _ctx = VideoScreen.this;

private Thread thread;
ProgressBar progressBar = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.phone_video_screen);



    progressBar = (ProgressBar) findViewById(R.id.progressbar);


    VideoView video = (VideoView) findViewById(R.id.videoView1);
    controller = new MediaController(VideoScreen.this);
    video.setMediaController(controller);

    video.setVideoPath(_url);
    video.requestFocus();
    video.start();
    progressBar.setVisibility(View.VISIBLE);
    video.setOnPreparedListener(new OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            // TODO Auto-generated method stub
            mp.start();
            progressBar.setVisibility(View.GONE);
            mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
                @Override
                public void onVideoSizeChanged(MediaPlayer mp, int arg1,
                        int arg2) {
                    progressBar.setVisibility(View.GONE);
                    mp.start();
                }
            });

        }
    });

 }
}

答案 1 :(得分:0)

videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw. canadavid));