MediaController doesn't work

前端 未结 3 572
小蘑菇
小蘑菇 2021-01-23 02:52

My layout that contains videoView

 

        
3条回答
  •  没有蜡笔的小新
    2021-01-23 03:19

    Try this :

    public static void playVideo(String urlPath) {
    
    VideoView mVideoview; // Added this line
    mVideoView =(VideoView) findViewByid(R.yourvideoviewid);
    
    try {
    // Start the MediaController
    MediaController mediacontroller = new MediaController(mContext);
    mediacontroller.setAnchorView(mVideoview);
    // Get the URL from String VideoURL
    Uri mVideo = Uri.parse(urlPath);
    mVideoview.setMediaController(mediacontroller);
    mVideoview.setVideoURI(mVideo);
    
    } catch (Exception e) {
    Log.e("Error", e.getMessage());
    e.printStackTrace();
    
    }
    
    mVideoview.requestFocus();
    mVideoview.setOnPreparedListener(new OnPreparedListener() {
    // Close the progress bar and play the video
    public void onPrepared(MediaPlayer mp) {
    mVideoview.start();
    
    }
    });
    
    mVideoview.setOnCompletionListener(new OnCompletionListener() {
    
    public void onCompletion(MediaPlayer mp) {
    
    }
    });
    }
    

提交回复
热议问题