Home > Blockchain >  error while play youtube video android studio
error while play youtube video android studio

Time:12-19

let me say i have listview of many youtube videos, i chosen 1 video from list by videoId. so this id has been passed in second activity, when i declare it. not work..

String videoId;

Bundle extras = getIntent().getExtras();
        if (extras != null) {
            videoId = extras.getString("videoId");
        }

    YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);
    getLifecycle().addObserver(youTubePlayerView);
    youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
        @Override
        public void onReady(@NonNull YouTubePlayer youTubePlayer) {
            
            youTubePlayer.loadVideo("uuvFkS7LTUk" , 0); // this work.
            youTubePlayer.loadVideo(videoId , 0); // this not work.
        }
    });

i faced same problem if i play that url use webview youtube embed link....

There is no error message

videoid = youtube video id example :

youtube.com/watch?v=MIy070Di10U (video id : MIy070Di10U)

image There is no error message

CodePudding user response:

nothing wrong in your codes, snice u read documentation:

Documentation

YouTubePlayer, Params:

videoId - id of the video

startSeconds - the time from which the video should start playing

loadVideo(videoId: String, startSeconds: Float)

make sure u passing Data without subtract, this mistake i made before.

  • Related