Iqra
Iqra

Reputation: 69

How to disable Touch while video is playing

I am developing a Toddler(kids) app in which I have shown the YouTube videos thumbnails in a recyclerview and whenever the user clicks on any of the listed thumbnails that video plays in full screen YouTube intent( and all the videos after that plays in order automatically). I am succeed in doing so. The problem is now I want to disable the touch screen while the video is playing. I thought of making transparent layout and to show this transparent layout as upper layer on YouTube Full screen video intent but i dont know how to attach this layout with Youtube video intent. Every kind of help is appreciated. below is my code:

main_activity.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="2"
    android:orientation="vertical"
    tools:context="com.example.pc.fkidshell.Main4Activity">

    <include layout="@layout/toolbar"
        android:id="@+id/my_thirdtoolbar"/>

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/VideoList"
        android:layout_below="@+id/my_thirdtoolbar"
        android:paddingTop="20dp"
        android:scrollbars="vertical">

    </android.support.v7.widget.RecyclerView>
</RelativeLayout>

video_row.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/thumbnailView"
        android:layout_gravity="center_horizontal"/>
</LinearLayout>

mainactivity.javaL

public class Main4Activity extends AppCompatActivity implements YouTubeThumbnailView.OnInitializedListener, YouTubeThumbnailLoader.OnThumbnailLoadedListener{
    Toolbar third_toolbar;
    YouTubeThumbnailView thumbnailView;
    YouTubeThumbnailLoader thumbnailLoader;
    RecyclerView VideoList;
    RecyclerView.Adapter adapter;
    List<Drawable> thumbnailViews;
    List<String> VideoId;
    String videoid;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        third_toolbar = (Toolbar) findViewById(R.id.my_thirdtoolbar);
        setSupportActionBar(third_toolbar);
        getSupportActionBar().setTitle(R.string.sectitle);
        getSupportActionBar().setIcon(R.drawable.tblogo);

        thumbnailViews = new ArrayList<>();
        VideoList = (RecyclerView) findViewById(R.id.VideoList);
        RecyclerView.LayoutManager layoutManager=new LinearLayoutManager(this);
        VideoList.setLayoutManager(layoutManager);
        adapter=new VideoListAdapter();
        VideoList.setAdapter(adapter);
        VideoId = new ArrayList<>();
        thumbnailView = new YouTubeThumbnailView(this);
        thumbnailView.initialize("API key", this);

    }

    @Override
    public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader youTubeThumbnailLoader) {
        thumbnailLoader = youTubeThumbnailLoader;
        youTubeThumbnailLoader.setOnThumbnailLoadedListener(Main4Activity.this);
        thumbnailLoader.setPlaylist("PLXRActLQ03oY_6AQb-5EMuKFYQA_fDE40");
    }

    @Override
    public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {

    }

    public void add() {
        adapter.notifyDataSetChanged();
        if (thumbnailLoader.hasNext())
            thumbnailLoader.next();
    }

    @Override
    public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
        thumbnailViews.add(youTubeThumbnailView.getDrawable());
        VideoId.add(s);
        add();
    }

    @Override
    public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader.ErrorReason errorReason) {

    }

    public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.MyView>{
        public class MyView extends RecyclerView.ViewHolder{
            ImageView imageView;
            public MyView(View itemView) {
                super(itemView);
                imageView= (ImageView) itemView.findViewById(R.id.thumbnailView);
            }
        }

        @Override
        public VideoListAdapter.MyView onCreateViewHolder(ViewGroup parent, int viewType) {
            View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.video_row, parent, false);
            return new MyView(itemView);
        }

        @Override
        public void onBindViewHolder(VideoListAdapter.MyView holder, final int position) {
            holder.imageView.setImageDrawable(thumbnailViews.get(position));
            holder.imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v)
                {
                    videoid=VideoId.get(position);
                    //startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v="+videoid+"&list=PLXRActLQ03oY_6AQb-5EMuKFYQA_fDE40")));
                    Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v="+videoid+"&index="+position+"&list=PLXRActLQ03oY_6AQb-5EMuKFYQA_fDE40"));
                    intent.putExtra("force_fullscreen",true);
                    startActivity(intent);


                   // Intent intenwt=YouTubeIntents.createPlayVideoIntent(Main4Activity.this,VideoId.get(position));
                   // intent.putExtra("force_fullscreen",true);
                    //startActivity(intent);
                }
            });
        }

        @Override
        public int getItemCount() {
            return thumbnailViews.size();
        }
    }
}

Upvotes: 2

Views: 1064

Answers (2)

Shweta Patel
Shweta Patel

Reputation: 728

Try with following this will help you

https://stackoverflow.com/a/28429348/7234534

Upvotes: 1

abielita
abielita

Reputation: 13469

As stated in this thread, this is impossible as you cannot override the home button even if it is soft or hard button. However, you can use third party apps like Untouch which is a very popular one, and can be found in the play store. (Search for Untouch or touch block and it should come up.) You may also check on this blog that discussed some workaround for your issue. Hope this helps!

Upvotes: 0

Related Questions