PierfrancescoSoffritti / android-youtube-player

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

FullScreen is not working #175

Closed edward1988 closed 6 years ago

edward1988 commented 6 years ago

This lib is awesome, video plaing very well, but i can not do the fullscreen. I used helper class from sample, but all that changes is screen orientation, and that all. My manifest contains this line android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout"

This is my code:

package shop.arvaal.com.shop;

public class CardProduct extends Fragment {
    private String attribute_text;
    private TextView attrib;
    private TextView tvPrice;
    private TextView currentColorText;
    private TextView tvPriceSpecial;
    private TextView option_hint;
    private FullScreenYouTube fullScreenHelper;
    private ArrayList<String> imageUrls;
    private JSONObject product;
    private ArrayList<String> currentColor;
    private YouTubePlayerView youtubePlayerView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.card_product, container, false);

         fullScreenHelper = new FullScreenYouTube(getActivity());
        mRecyclerView = view.findViewById(R.id.my_recycler_view);
        mLayoutManager = new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL, false);
        SnapHelper snapHelper = new LinearSnapHelper();
        snapHelper.attachToRecyclerView(mRecyclerView);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setHasFixedSize(true);
        indicator = view.findViewById(R.id.circleIndicator);

       youtubePlayerView = view.findViewById(R.id.youtube_player_view);
        getLifecycle().addObserver(youtubePlayerView);

       final TextView button_text = view.findViewById(R.id.description_text_button);
       button_text.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               button_text.setText(decription_product.isExpanded() ? R.string.expand : R.string.collapse);
               decription_product.toggle();

           }
       });
        makeJsonObjectRequest(urlJsonObj+getArguments().getInt("someInt")+key);
            return view;
        }

******************************

                    if(product.getString("youtube_code").equals("empty")){
                        youtubeContainer.setVisibility(View.GONE);
                    }else {
                        youtubePlayerView.initialize(new YouTubePlayerInitListener() {
                            @Override
                            public void onInitSuccess(@NonNull final YouTubePlayer initializedYouTubePlayer) {
                                initializedYouTubePlayer.addListener(new AbstractYouTubePlayerListener() {
                                    @Override
                                    public void onReady() {
                                        initializedYouTubePlayer.cueVideo(product.optString("youtube_code"), 0);
                                    }
                                });
                                addFullScreenListenerToPlayer(initializedYouTubePlayer);
                            }
                        }, true);
                    }

     *********************************************
    private void addFullScreenListenerToPlayer(final YouTubePlayer youTubePlayer) {
        youtubePlayerView.addFullScreenListener(new YouTubePlayerFullScreenListener() {
            @Override
            public void onYouTubePlayerEnterFullScreen() {
                getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                fullScreenHelper.enterFullScreen()
            }

            @Override
            public void onYouTubePlayerExitFullScreen() {
                getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                fullScreenHelper.exitFullScreen();
            }
        });
    }
    @Override public void onDestroy() {
        super.onDestroy();
        youtubePlayerView.release()
    }
}

This is helper class:

package shop.arvaal.com.shop;
import android.app.Activity;
import android.view.View;
public class FullScreenYouTube{
private Activity context;
private View[] views;

/**
 * @param context
 * @param views to hide/show
 */
public FullScreenYouTube(Activity context, View ... views) {
        this.context = context;
        this.views = views;
        }

/**
 * call this method to enter full screen
 */
public void enterFullScreen() {
       View decorView = context.getWindow().getDecorView();

        hideSystemUI(decorView);

        for(View view : views) {
        view.setVisibility(View.GONE);
        view.invalidate();
        }
        }

/**
 * call this method to exit full screen
 */
public void exitFullScreen() {
       View decorView = context.getWindow().getDecorView();

        showSystemUI(decorView);

        for(View view : views) {
        view.setVisibility(View.VISIBLE);
        view.invalidate();
        }
        }

private void hideSystemUI(View mDecorView) {
        mDecorView.setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_FULLSCREEN
        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }

private void showSystemUI(View mDecorView) {
        mDecorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
        }
PierfrancescoSoffritti commented 6 years ago

Hi, try to understand how the sample app is doing it :)

edward1988 commented 6 years ago

i'm trying, but nothing works. Сan tell me where should I look?

PierfrancescoSoffritti commented 6 years ago

You should look at the basic example.

ItsCalebJones commented 5 years ago

It think the problem we're running into is persisting the fragment properly. Persisting the activities not hard.

borjanspan commented 3 years ago

Hi @edward1988, The problem is with the recyclerView item and its' height. You should either change recyclerView Item's heigth on 'full screen' click, or navigate to other Activity/Fragment which has only YoutubePlayerView.

Dkathayat commented 2 years ago

I am not even getting the option to implement full screen in XML

PierfrancescoSoffritti commented 2 years ago

@Dkathayat That has been removed with the latest version of the library.

AbdullahGhanim2007 commented 2 years ago

so how can i full screen the video pls help