- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
问这个问题是因为我搜索了几个小时后没有找到解决方案/建议。所有回答的解决方案都带有 Fragment。我在寻找 ViewPagerAdapter 和 FrameLayout。
我的 ViewPagerAdapter xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/promotion_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/some_image"
android:layout_width="match_parent"
android:layout_height="@dimen/view_pager_height"
android:scaleType="fitXY" />
<FrameLayout
android:id="@+id/youtube_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
//Some other view items
</RelativeLayout>
我的 ViewPagerAdapter Java 代码:
public class ArticleViewPagerAdapter extends PagerAdapter {
public String TAG = ArticleViewPagerAdapter.class.getSimpleName();
private ArrayList<Article> mArticleList = new ArrayList<>();
private Activity mContext;
private LayoutInflater mLayoutInflater;
private FragmentManager mFragmentManger;
private YouTubePlayerListener mYouTubePlayerListener;
public ArticleViewPagerAdapter(Activity context, ArrayList<Article> articleList, FragmentManager fragmentManager, YouTubePlayerListener youTubePlayerListener) {
this.mContext = context;
this.mArticleList = articleList;
this.mFragmentManger = fragmentManager;
this.mYouTubePlayerListener = youTubePlayerListener;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mArticleList.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == (object);
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
View itemView = mLayoutInflater.inflate(R.layout.activity_news, container,
false);
itemView.setTag(position);
updateView(itemView, position);
((ViewPager) container).addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
private void updateView(View itemView, int position) {
final int index = position;
final View finalView = itemView;
//Initializing the view items
final ImageView mNewsImage = itemView.findViewById(R.id.some_image);
final FrameLayout mYoutubeFragment = itemView.findViewById(R.id.youtube_fragment);
//Let's Test using this
final YouTubePlayerSupportFragment youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
ResArticle articleResponse = response.body(); //Got response from API
if (articleResponse != null && articleResponse.getData() != null) {
final Article article = articleResponse.getData();
final String pageUrl = SHARE_BASE_URL + article.getArticleId();
if (article != null) {
if (article.getArticleType()==Constants.ARTICLE_TYPE_NEWS) {
//Basically setting visibility But you can ignore this part
mNewsImage.setVisibility(View.VISIBLE);
mYoutubeFragment.setVisibility(View.GONE);
}
if(article.getArticleType()==Constants.ARTICLE_TYPE_VIDEO) {
Log.d(TAG,"Article Type is Video");
mYoutubeFragment.setVisibility(View.VISIBLE);
mNewsImage.setVisibility(View.GONE);
youTubePlayerFragment.initialize(mContext.getString(R.string.web_client_id), new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {
youTubePlayer.setShowFullscreenButton(false);
youTubePlayer.cueVideo("video_id");
if (mYouTubePlayerListener!=null)
mYouTubePlayerListener.setYouTubePlayer(youTubePlayer);
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.e(TAG, "Youtube Video initialization failed");
}
});
FragmentTransaction transaction = mFragmentManger.beginTransaction();
transaction.replace(R.id.youtube_fragment, youTubePlayerFragment).commit();
}
}
} else {
Toast.makeText(mContext, mContext.getString(R.string.article_info_not_found), Toast.LENGTH_SHORT).show();
Log.e(TAG, "Article info not found");
}
}
}
}
我是从 Activity 而非 YouTubeBaseActivity
调用适配器。
问题:YouTube 视频播放因播放器顶部未经授权的覆盖而停止。 YouTubePlayerView 不包含在其祖先 android.widget.FrameLayout 中。祖先边缘与 YouTubePlayerView 边缘之间的距离为:left: 0, top: 0, right: 0, bottom: 0(这些都应该是正数)。
为什么我会收到错误消息?当我使用 ViewPager 加载多个 YouTube 播放器时。正如我们所知,viewpager 加载下一个、上一个和当前项目。因此,当前的 YouTube 视频会被初始化,下一个视频也会被初始化。但是由于当前的 YouTubePlayer 覆盖了下一个(预加载)。
请帮忙。或者我应该使用任何库来加载 YouTube 视频。
最佳答案
通过移除布局中 YouTubePlayerView 中的填充来解决此问题。所以你的布局看起来像这样:
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/video_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000" />
为什么在适配器中使用 instantiateItem
而不是 getItem
?
关于android - ViewPagerAdapter : YouTube video playback stopped due to unauthorized overlay on top of player,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49383873/
你能解释一下两者之间的区别吗 和 ? 最佳答案 通过使用 .您可以添加多个源元素。多个源元素可以链接到不同的视频文件。浏览器将使用第一个识别的格式。
我正在使用 ImagePickerController 处理 iPhone 视频捕获。我已经设置了图像选择器 Controller 的属性。我用它来将视频的最大长度设置为 60 秒。 imagePic
我正在制作一个进行基本视频处理的应用程序。我成功地合并到视频(视频上的视频)。 如何将左上角的小视频裁剪成一个圆圈? 最佳答案 如果您想导出该视频,您需要: 创建 CALayer,它将成为您的视频层的
我正在使用 SVT-AV1 和 FFMPEG 将视频编码为 AV1 视频和 opus 音频编解码器(.webm),它工作正常,除了视频搜索不起作用(非常糟糕)。当我寻找时,CPU 使用率会上升,并且需
在 Adobe Muse 中使用 VIDEO.JS 目前我已将海报图像配置为在视频开头显示, 当视频结束时,我希望海报图像重新出现。谢谢你的帮助! 最佳答案 将来最好的方法是通过 css。我只是a
我目前正在尝试从单张图片 (1980*1024) 生成视频 这是我的命令: ffmpeg -threads 8 -r 1 -loop 1 -i "C:\Library\Titling\__Resour
我想从 HTML 获取框架 javascript 中的组件,以便我可以处理它们然后输出到 Canvas 最佳答案 看看这个代码笔:Demo var videoId = 'video'; va
我已经使用 video.js 一段时间了,正在寻找响应式解决方案。我看到 4.6 声称是这样,但无法开始工作。我在文档中找不到任何关于使其响应的内容。我基本上只需要它保持在容器的 100% 并保持其纵
我正在寻找任何用于设置视频流服务器的现代资源。最好是开源解决方案。 我对此的搜索导致了很多死胡同。我也确实需要构建自己的服务而不是支付服务费用。 最佳答案 要设置您自己的视频流服务器,您应该从以下组件
如何在处理流媒体或网络视频时拦截“无法播放视频”对话框? 我尝试了以下操作并能够显示我的自定义错误消息。但最重要的是,我仍然收到 Android MediaPlayer 错误对话框“无法播放视频”。
它使我的视频居中并将控件放置在 div 底部但视频流出。在 css 样式表中,css 似乎无法识别。样式表中的 cos 颜色为黑色。我使用 Chrome 。 div.video_div{ width:
在 HTML5 video 元素中,您定义 type 属性的值始终以 video 开头。从元素是视频不是已经很明显,它是视频类型吗?为什么需要这样的视频:type="video/mp4",不应该只是t
我想通过 jQuery 或 Javascript 检测 html5 标签内的特定视频何时已完全加载(我的意思是,下载到浏览器的缓存中)。视频具有 preload = "auto"属性。 我尽我所能做到
HTML5 带来或将带来和 标签等等。自从我听说了他们,读了之后更是如此Why do we have an img element?特别是Jay C. Weber's message back fro
我正在制定一个 Web 应用程序的详细信息,该应用程序涉及顺序加载一长串(非常短的)视频剪辑,一个接一个,用户偶尔会输入建立新的视频剪辑加载方向. 我希望能够让浏览器一次预加载五个视频剪辑。然而,我们
我想知道 HTML5 标签现在支持.avi 格式视频文件的播放。 最佳答案 简短回答:否。改用 WebM 或 Ogg。 This article几乎涵盖了您需要了解的有关 的所有信息元素,包括哪些浏
尽管它似乎处于某种危险之中,但开放视频标准是一个好主意。我看到了一些关于运动跟踪的演示——只是概念验证,但仍然很有趣。现在,我要说的是,如果可以访问用户的网络摄像头,像这样的概念真的会是一个收获……想
我正在尝试使用 php-facebook-sdk 并借助 curl Facebook API 创建广告。 我已经使用 curl 上传了我的视频,它返回了一个 ID。现在,该视频 ID 将用于添加广告,
我正在使用 Video.js在我的网站上显示视频的插件。 我想删除画中画图标。我已经尝试了几个小时,但没有成功。 我做错了什么? 最佳答案 它应该是 data-setup='{"cont
使用 MediaRecorder 从 SurfaceView 录制视频 录音机 recorderProfile = CamcorderProfile.get( CamcorderProfile.QUA
我是一名优秀的程序员,十分优秀!