如何在播放视频时禁用Touch

时间:2016-12-01 00:16:58

标签: java android android-intent youtube-api

我正在开发一个幼儿(儿童)应用程序,在该应用程序中,我在回收者视图中显示了YouTube视频缩略图,并且每当用户点击视频以全屏YouTube意图播放的任何列出的缩略图时(以及之后的所有视频)自动播放)。我成功了。问题是现在我想在视频播放时禁用触摸屏。我想要制作透明的布局,并在YouTube全屏视频意图中将此透明布局显示为上层,但我不知道如何使用Youtube视频意图附加此布局。 各种帮助表示赞赏。 下面是我的代码:

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();
        }
    }
}

2 个答案:

答案 0 :(得分:1)

尝试以下操作可以帮助您

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

答案 1 :(得分:0)

如此thread中所述,这是不可能的,因为即使它是软按钮或硬按钮也无法覆盖主页按钮。但是,您可以使用非常受欢迎的第三方应用,例如Untouch,并且可以在Play商店中找到。 (搜索Untouch或触摸屏,它应该出现。)您也可以查看讨论了您的问题的一些解决方法的blog。希望这有帮助!