onInitializationSuccess从未调用

时间:2015-10-13 15:14:50

标签: android youtube-api

我的应用程序在三星S3(4.3)中播放youtube视频没有问题,但是当我在HUAWEI ASCEND P8(5.0),Nexus 5(6.0)和BQ Aquaris M5(5.0.2)中打开它时,onInitializationSuccess方法永远不会被调用< / p>

这是我的代码:

public class YoutubePlayerActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {

    private static final int RECOVERY_REQUEST = 1;
    private YouTubePlayerView youTubeView;

    private String videoUrl;

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

        videoUrl = getIntent().getExtras().getString("url");

        youTubeView = (YouTubePlayerView) findViewById(R.id.youtubeplayerview);
        youTubeView.initialize(API_KEY, this);
    }

    @Override
    public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            player.loadVideo(this.videoUrl.split("=")[1]);
        }
    }

    @Override
    public void onInitializationFailure(Provider provider, YouTubeInitializationResult errorReason) {
        if (errorReason.isUserRecoverableError()) {
            errorReason.getErrorDialog(this, RECOVERY_REQUEST).show();
        } else {
            String error = String.format(getString(R.string.error), errorReason.toString());
            Toast.makeText(this, error, Toast.LENGTH_LONG).show();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == RECOVERY_REQUEST) {
            // Retry initialization if user performed a recovery action
            getYouTubePlayerProvider().initialize(API_KEY, this);
        }
    }

    protected Provider getYouTubePlayerProvider() {
        return youTubeView;
    }

}

有人能帮助我吗? 非常感谢

0 个答案:

没有答案