Video not playing in Android

前端 未结 5 425
情歌与酒
情歌与酒 2020-12-30 12:33

Video not working properly in the below mentioned code. What could be the problem for this?

MediaController mediaController = new MediaController(getBaseCont         


        
5条回答
  •  旧巷少年郎
    2020-12-30 13:00

    private VideoView mVideoView;
    
    @Override
        public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
    
            setContentView(R.layout.main);
            mVideoView = (VideoView) findViewById(R.id.surface_view);
        }
    
        private void playVideo() {
            try {
                final String path = "http://www.youtube.com/v/wwI2w2YHkCQ?fs=1"
    
                System.out.println("path  "+path);
                Log.v(TAG, "path: " + path);
                if (path == null || path.length() == 0) {
                    Toast.makeText(VideoViewDemo.this, "File URL/path is empty",
                            Toast.LENGTH_LONG).show();
                }
                else {
                    System.out.println("else  ");
                    // If the path has not changed, just start the media player
                    if (path.equals(current) && mVideoView != null) {
                        System.out.println("mVideoView.start()  ");
    
                        mVideoView.start();
                        mVideoView.requestFocus();
                        return;
                    }
                    current = path;
                    //mVideoView.setVideoPath(getDataSource(path));
                    mVideoView.setVideoURI(Uri.parse(path));
                    mVideoView.start();
                    mVideoView.requestFocus();
                }
            }
            catch (Exception e) {
                Log.e(TAG, "error: " + e.getMessage(), e);
                if (mVideoView != null) {
                    mVideoView.stopPlayback();
                }
            }
        }
    

    main.xml

    
    
        
    
        
            
    
            
            
            
        
    
        
        
    
    

提交回复
热议问题