Android youtube播放器加载视频方法调用onvideo结束而不是加载视频

时间:2017-09-08 13:56:05

标签: android youtube-api

Min_sdk = 11 我已经在我的应用程序的其中一个屏幕中集成了YouTube播放器视图,并且第一个视频通过调用所有回调侦听器方法开始完美播放但是当我尝试加载视频时它不起作用而是调用onvideo结束方法而不播放视频。

我在初始化方法中的变量youtubeplayer1中获取了YouTube播放器,如下面的代码所示

youTubePlayer.setPlaybackEventListener(new MHPlaybackEventListener());
        youTubePlayer.setPlayerStateChangeListener(new MHPlayerStateChangeListener());
        youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
        youTubePlayer.cueVideo(video_url);
        youTubePlayer1 = youTubePlayer;

我使用该变量暂停和播放视频并尝试加载视频,如下所示

  if(youTubePlayer1!=null)
            {
                youTubePlayer1.cueVideo(video_url);
            }

MHPlayerstatechangedlistener

    @Override
    public void onAdStarted() {
        System.out.println("onAdStarted PlayerStateChangeListener..."+" is started="+isStarted);
        //Toast.makeText(youtube_player.this, "onAdStarted video...", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onError(YouTubePlayer.ErrorReason arg0) {
        System.out.println("onError PlayerStateChangeListener..."+" is started="+isStarted);
        //Toast.makeText(youtube_player.this, "onError video...", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onLoaded(String arg0) {
        System.out.println("onLoaded PlayerStateChangeListener... (starting play and timer)"+" is started="+isStarted);
            youTubePlayer1.play();

        startTimer(timeRemaining);
        System.out.println("onLoaded PlayerStateChangeListener... (end)"+" is started="+isStarted);
    }

    @Override
    public void onLoading() {
        System.out.println("onLoading PlayerStateChangeListener..."+" is started="+isStarted);
        //  library.messageBox("Hello");
        //Toast.makeText(youtube_player.this, "onLoading video...", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onVideoEnded() {
        System.out.println("onVideoEnded PlayerStateChangeListener..."+" is started="+isStarted);
        //Toast.makeText(youtube_player.this, "onVideoEnded video...", Toast.LENGTH_SHORT).show();
    //  startTimer(1); // we are displaying time-1,
    }

    @Override
    public void onVideoStarted() {
        System.out.println("onVideoStarted PlayerStateChangeListener..."+" is started="+isStarted);
        //Toast.makeText(youtube_player.this, "onVideoStarted video...", Toast.LENGTH_SHORT).show();
    }

}

MHPlaybackEventListener

    @Override
    public void onBuffering(boolean arg0) {
        System.out.println("onBuffering PlaybackEventListener..."+" is started="+isStarted);
        //Toast.makeText(youtube_player.this, "onBuffering video...", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onPaused() {
        // TODO: pause the timer as well
        System.out.println("onPaused PlaybackEventListener..."+" is started="+isStarted);
        //System.out.println("");
        //Toast.makeText(youtube_player.this, "onPaused video...", Toast.LENGTH_SHORT).show();
                    isStarted =false;
    }

    @Override
    public void onPlaying() {
        System.out.println("onPlaying PlaybackEventListener..."+" is started="+isStarted);
        //Toast.makeText(youtube_player.this, "onPlaying video...", Toast.LENGTH_SHORT).show();

        isStarted =true;
                }

    @Override
    public void onSeekTo(int arg0) {
        System.out.println("onSeekTo PlaybackEventListener..."+" is started="+isStarted);
        //Toast.makeText(youtube_player.this, "onSeekTo video...", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onStopped() {
        // TODO: stop the timer as well
        isStarted =false;
    }
}

我尝试加载视频方法,再次初始化youtube播放器视图但没有任何效果。这一切只调用onvideoended方法

有人可以帮我解决这个问题吗?

谢谢

0 个答案:

没有答案