在Android中选择像YouTube这样的视频质量

时间:2018-07-30 11:44:02

标签: android youtube android-videoview

我想制作一个示例Android应用程序,从服务器获取视频URL,并且必须以VideoView播放视频。已经实现了。现在,我想在VideoView中放置一个按钮,在其中可以选择

之类的视频质量。

YOUTUBE Stream Quality Selection

我的VideoView代码是

public class MainActivity extends Activity {

VideoView simpleVideoView;
MediaController mediaControls;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Find your VideoView in your video_main.xml layout
    simpleVideoView = (VideoView) findViewById(R.id.simpleVideoView);

    if (mediaControls == null) {
        // create an object of media controller class
        mediaControls = new MediaController(MainActivity.this);
        mediaControls.setAnchorView(simpleVideoView);
    }
    // set the media controller for video view
    simpleVideoView.setMediaController(mediaControls);
    // set the uri for the video view
    simpleVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.fishvideo));
    // start a video
    simpleVideoView.start();

    // implement on completion listener on video view
    simpleVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            Toast.makeText(getApplicationContext(), "Thank You...!!!", Toast.LENGTH_LONG).show(); // display a toast when an video is completed
        }
    });
    simpleVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            Toast.makeText(getApplicationContext(), "Oops An Error Occur While Playing Video...!!!", Toast.LENGTH_LONG).show(); // display a toast when an error is occured while playing an video
            return false;
        }
    });
}

}

我想基于流质量选择加载视频。请指导我。图书馆的任何示例代码都很棒

0 个答案:

没有答案