How to play Youtube video in ExoPlayer in Android?

后端 未结 4 1132
野的像风
野的像风 2020-12-07 16:35

I am trying to play youtube video in exoplayer but here is some confusion I don\'t know what is DASH url, I have only real youtube url like \"https://www.youtube.com/watch

4条回答
  •  执念已碎
    2020-12-07 17:24

    I had the same issue but i finally found the simplest solution and its working so good

    1. First you need to call this url..

      HTTP GET: https://www.youtube.com/get_video_info?&video_id=[video_id]&el=info&ps=default&eurl=&gl=US&hl=en

    and don't forget to change the last id with the target one.

    1. now you will get notice to download a file called get_video_info with no extesion.
    2. try to open this file using notepad and so.
    3. Now you have the right data but you can't read it because its encoded You need HTML decoder to reed this data use this one: http://meyerweb.com/eric/tools/dencoder/

    -just paste your data and press decode a several times to ensure it decoded well

    finally search for a key called dashmpd

    and enjoy ur URL

    Or use this Simple Solution

    private void extractYoutubeUrl() {
        @SuppressLint("StaticFieldLeak") YouTubeExtractor mExtractor = new YouTubeExtractor(this) {
            @Override
            protected void onExtractionComplete(SparseArray sparseArray, VideoMeta videoMeta) {
                if (sparseArray != null) {
                    playVideo(sparseArray.get(17).getUrl());
                }
            }
        };
        mExtractor.extract(mYoutubeLink, true, true);
    

    implementation 'com.github.HaarigerHarald:android-youtubeExtractor:v1.7.0'
    

提交回复
热议问题