当前位置:  开发笔记 > 前端 > 正文

YouTube播放器Api从切换到全屏时开始重新加载视频

如何解决《YouTube播放器Api从切换到全屏时开始重新加载视频》经验,为你挑选了1个好方法。

我试图在我的应用程序中集成Youtube播放器api.但是,当我切换到全屏时,会出现一些问题:

    视频从头开始重新加载.

    在全屏模式下按后退按钮时,应用程序将被强制进入横向方向.

公共类YouTubeVideoElement extends Element实现了YouTubePlayer.OnInitializedListener {

private final String DEVELOPER_KEY = "MY_KEY";
private static final int RECOVERY_DIALOG_REQUEST = 1;

    private RelativeLayout.LayoutParams layoutParams;

    private YouTubePlayerFragment playerFragment;
    private View playerView;
    private ViewGroup viewFrame;
    public State state;
    private Dialog errorDialog;
    private Context context;

    public YouTubeVideoElement(Context context) {
        this.context = context;

    }


    @Override
    public String getType() {
        return null;
    }

    @Override
    public ViewGroup getView() {
        return viewFrame;
    }

    @Override
    public ViewGroup populateView(Context context, JsonObject data, Map style) {

        viewFrame = new FrameLayout(context);
        playerView = new FrameLayout(context);
        playerView.setId(R.id.player_view);
        playerView.setVisibility(View.INVISIBLE);
        viewFrame.addView(playerView, -1, -1);
        playerView.setVisibility(View.VISIBLE);
        playerFragment = YouTubePlayerFragment.newInstance();
        playerFragment.initialize(DEVELOPER_KEY, this);
        ((Activity) context).getFragmentManager().beginTransaction().add(R.id.player_view, playerFragment).commit();
        return viewFrame;
    }

    public RelativeLayout.LayoutParams getLayoutParams() {
        return layoutParams;
    }

    public YouTubeVideoElement setLayoutParams(RelativeLayout.LayoutParams layoutParams) {
        this.layoutParams = layoutParams;
        return this;
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {

        Log.d("xxx", "onInitSuccess YTP");
        if (!wasRestored) {
            player.cueVideo("nCgQDjiotG0");
        }
    }


    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult errorReason) {

        Log.d("xxx", "onInitFailure YTP");
        if (errorReason.isUserRecoverableError()) {
            errorReason.getErrorDialog((Activity) context, RECOVERY_DIALOG_REQUEST).show();
        } else {
            //String errorMessage = String.format(getString(R.string.error_player), errorReason.toString());
            Toast.makeText(context, "error", Toast.LENGTH_LONG).show();
        }
    }
}

小智.. 9

请尝试在AndroidManifest文件中更新:

  

列出活动将自行处理的配置更改.在运行时发生配置更改时,默认情况下会关闭并重新启动活动,但声明具有此属性的配置将阻止活动重新启动.相反,活动仍在运行,并调用其onConfigurationChanged()方法.

从官方的Android指南.



1> 小智..:

请尝试在AndroidManifest文件中更新:

  

列出活动将自行处理的配置更改.在运行时发生配置更改时,默认情况下会关闭并重新启动活动,但声明具有此属性的配置将阻止活动重新启动.相反,活动仍在运行,并调用其onConfigurationChanged()方法.

从官方的Android指南.

推荐阅读
k78283381
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有