视频播放时如何禁用触摸



我正在开发一个幼儿(儿童)应用程序,我在recyclerview中显示了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();
        }
    }
}

尝试以下此操作将帮助您

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

正如该线程中所述,这是不可能的,因为即使柔软或硬按钮也无法覆盖主按钮。但是,您可以使用非常受欢迎的第三方应用程序,可以在Play商店中找到。(搜索Untouch或Touch Block,应该出现。)您还可以检查此博客,该博客讨论了有关您的问题的解决方法。希望这会有所帮助!

相关内容

  • 没有找到相关文章

最新更新