PierfrancescoSoffritti / android-youtube-player

YouTube Player library for Android and Chromecast, stable and customizable.
https://pierfrancescosoffritti.github.io/android-youtube-player/
MIT License
3.43k stars 764 forks source link

"Uncaught TypeError: YouTubePlayerBridge.sendYouTubeIFrameAPIReady is not a function", source: https://www.youtube.com/ (40) #515

Open sachinvarma opened 4 years ago

sachinvarma commented 4 years ago

Hi, First of all, you have done an awesome work by creating this Library, really appreciating on this. I'm facing some issues please have a look on to it.

I'm trying to load youtube videos in RecyclerView, but it's is not playing and throwing error as ""Uncaught TypeError: YouTubePlayerBridge.sendYouTubeIFrameAPIReady is not a function", source: https://www.youtube.com/ (40)"

Using -> implementation 'com.github.PierfrancescoSoffritti:AndroidYouTubePlayer:10.0.5'

Activity:

public class RecyclerViewActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view_example);

    RecyclerView recyclerView = findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);

    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(mLayoutManager);

    String[] videoIds = {"6JYIGclVQdw", "LvetJ9U_tVY", "6JYIGclVQdw", "LvetJ9U_tVY", "6JYIGclVQdw", "LvetJ9U_tVY", "6JYIGclVQdw", "LvetJ9U_tVY", "6JYIGclVQdw", "LvetJ9U_tVY", "6JYIGclVQdw", "LvetJ9U_tVY"};

    RecyclerView.Adapter recyclerViewAdapter = new RecyclerViewAdapter(videoIds, this.getLifecycle());
    recyclerView.setAdapter(recyclerViewAdapter);
}

}

Adapter:

class RecyclerViewAdapter extends RecyclerView.Adapter { private String[] videoIds; private Lifecycle lifecycle;

RecyclerViewAdapter(String[] videoIds, Lifecycle lifecycle) {
    this.videoIds = videoIds;
    this.lifecycle = lifecycle;
}

@NonNull
@Override
public RecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    YouTubePlayerView youTubePlayerView = (YouTubePlayerView) LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view_item, parent, false);
    lifecycle.addObserver(youTubePlayerView);

    return new ViewHolder(youTubePlayerView);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
    viewHolder.cueVideo(videoIds[position]);

}

@Override
public int getItemCount() {
    return videoIds.length;
}

static class ViewHolder extends RecyclerView.ViewHolder {
    private YouTubePlayerView youTubePlayerView;
    private YouTubePlayer youTubePlayer;
    private String currentVideoId;

    ViewHolder(YouTubePlayerView playerView) {
        super(playerView);
        youTubePlayerView = playerView;

        youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
            @Override
            public void onReady(@NonNull YouTubePlayer initializedYouTubePlayer) {
                youTubePlayer = initializedYouTubePlayer;
                youTubePlayer.cueVideo(currentVideoId, 0f);
            }
        });
    }

    void cueVideo(String videoId) {
        currentVideoId = videoId;

        if(youTubePlayer == null)
            return;

        youTubePlayer.cueVideo(videoId, 0f);
    }
}

}

Not understanding why this is happening, It's continuously showing loader.

Logcat:

2020-01-30 21:39:34.745 20386-20386/I/chromium: [INFO:CONSOLE(40)] "Uncaught TypeError: YouTubePlayerBridge.sendYouTubeIFrameAPIReady is not a function", source: https://www.youtube.com/ (40) 2020-01-30 21:39:34.750 20386-20386/s I/chromium: [INFO:CONSOLE(40)] "Uncaught TypeError: YouTubePlayerBridge.sendYouTubeIFrameAPIReady is not a function", source: https://www.youtube.com/ (40) 2020-01-30 21:39:34.775 20386-20386/ I/chromium: [INFO:CONSOLE(40)] "Uncaught TypeError: YouTubePlayerBridge.sendYouTubeIFrameAPIReady is not a function", source: https://www.youtube.com/ (40) 2020-01-30 21:39:38.122 20386-20420/ V/FA: Inactivity, disconnecting from the service.

mugabi0978 commented 4 years ago

You need to use the latest google-services library similar to what the library uses.

PierfrancescoSoffritti commented 4 years ago

Does your app's manifest have internet access permission?

sachinvarma commented 4 years ago

Does your app's manifest have internet access permission?

Yes, internet access permission is already given.

codefury commented 4 years ago

@PierfrancescoSoffritti this is happening with proguard enabled.

@sachinvarma were you able to fix the problem?

NaqiControl commented 4 years ago

same problem with me.

W/cr_media: Requires BLUETOOTH permission W/AudioCapabilities: Unsupported mime audio/mpeg-L2 W/AudioCapabilities: Unsupported mime audio/x-adpcm-ms W/AudioCapabilities: Unsupported mime audio/x-adpcm-dvi-ima W/AudioCapabilities: Unsupported mime audio/ape W/AudioCapabilities: Unsupported mime audio/alac W/AudioCapabilities: Unsupported mime audio/x-adpcm-ms W/AudioCapabilities: Unsupported mime audio/x-adpcm-dvi-ima W/VideoCapabilities: Unrecognized profile/level 1/32 for video/mp4v-es W/VideoCapabilities: Unrecognized profile/level 32768/2 for video/mp4v-es W/VideoCapabilities: Unrecognized profile/level 32768/64 for video/mp4v-es W/libEGL: [ANDROID_RECORDABLE] format: 1 W/VideoCapabilities: Unsupported mime video/divx W/VideoCapabilities: Unsupported mime video/divx3 W/VideoCapabilities: Unsupported mime video/xvid W/VideoCapabilities: Unsupported mime video/flv1 W/VideoCapabilities: Unrecognized profile/level 1/32 for video/mp4v-es I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es W/cr_MediaCodecUtil: Codec OMX.MTK.VIDEO.ENCODER.AVC is disabled due to SDK version 24 W/cr_MediaCodecUtil: HW encoder for video/avc is not available on this device. I/chromium: [INFO:CONSOLE(40)] "Uncaught TypeError: YouTubePlayerBridge.sendYouTubeIFrameAPIReady is not a function", source: https://www.youtube.com/ (40)

NaqiControl commented 4 years ago

@PierfrancescoSoffritti this is happening with proguard enabled.

@sachinvarma were you able to fix the problem?

I cant fix it please help.

NaqiControl commented 4 years ago

proguard

setting minifyEnabled = false fix my issue finally thanks @codefury

hdtechnoworx commented 3 years ago

I/chromium: [INFO:CONSOLE(0)] "The page at https://www.youtube.com/ displayed insecure content from android-webview:default_video_poster/-3066190324635200840. ", source: https://www.youtube.com/ (0) D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 196608 gralloc_alloc: Creating ashmem region of size 196608 D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 393216 D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 393216 I/OMXClient: Using client-side OMX mux. E/OMXNodeInstance: OMX_GetExtensionIndex OMX.google.android.index.storeMetaDataInBuffers failed E/ACodec: [OMX.google.h264.decoder] storeMetaDataInBuffers failed w/ err -2147483648 I/OMXClient: Using client-side OMX mux. D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 32768 E/SoftAVC: Decoder failed: -2 E/ACodec: [OMX.google.h264.decoder] ERROR(0x80001001) I/SoftAAC2: Reconfiguring decoder: 0->44100 Hz, 0->2 channels E/MediaCodec: Codec reported an error. (omx error 0x80001001, internalError -2147483648) E/MediaCodecBridge: Cannot dequeue output buffer java.lang.IllegalStateException I/chromium: [INFO:CONSOLE(0)] "The page at https://www.youtube.com/ displayed insecure content from android-webview:default_video_poster/-3066190324635200840. ", source: https://www.youtube.com/ (0) I/OMXClient: Using client-side OMX mux. E/OMXNodeInstance: OMX_GetExtensionIndex OMX.google.android.index.storeMetaDataInBuffers failed E/ACodec: [OMX.google.h264.decoder] storeMetaDataInBuffers failed w/ err -2147483648 I/OMXClient: Using client-side OMX mux. I/SoftAAC2: Reconfiguring decoder: 0->44100 Hz, 0->2 channels E/SoftAVC: Decoder failed: -2 E/ACodec: [OMX.google.h264.decoder] ERROR(0x80001001) E/MediaCodec: Codec reported an error. (omx error 0x80001001, internalError -2147483648) E/MediaCodecBridge: Cannot dequeue output buffer java.lang.IllegalStateException I/chromium: [INFO:CONSOLE(0)] "The page at https://www.youtube.com/ displayed insecure content from android-webview:default_video_poster/-3066190324635200840. ", source: https://www.youtube.com/ (0)

getting this in android API 19 anyone have any solution for this issue?

HassanAhamd commented 2 years ago

Hi, Everyone this issue is happening because of Proguard in simple words minifyEnabled false issue will not appear but if you enable the proguard this issue will appear and the screen will stuck on Loader. still trying to find the issue but did'nt succed if anyone fix this with Progurad enable let me know ! Thank You !

HassanAhamd commented 2 years ago

Hi, Everyone this issue is happening because of Proguard in simple words minifyEnabled false issue will not appear but if you enable the proguard this issue will appear and the screen will stuck on Loader. still trying to find the issue but did'nt succed if anyone fix this with Progurad enable let me know ! Thank You !

I fix it Add these lines in Proguard-rules.pro -keepclassmembers class com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayerBridge { public *; } -keep class com.pierfrancescosoffritti.androidyoutubeplayer.* { ; } -keepnames class com.pierfrancescosoffritti.youtubeplayer.*

HassanAhamd commented 2 years ago

I fix it Add these lines in Proguard-rules.pro -keepclassmembers class com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayerBridge { public ; } -keep class com.pierfrancescosoffritti.androidyoutubeplayer.* { ; } -keepnames class com.pierfrancescosoffritti.youtubeplayer.