gpt4 book ai didi

java - 如何在播放视频时禁用触摸

转载 作者:行者123 更新时间:2023-11-30 10:35:51 26 4
gpt4 key购买 nike

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

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

关于java - 如何在播放视频时禁用触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40900560/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com