- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我没有运气让 youtube-api 在 android 上工作。我正在努力获得最低限度的工作 - 只需通过公共(public)访问(无 oauth)播放视频。我有一个来自谷歌的 key ,我在我的模拟器上安装了 youtube 应用程序。我非常有信心这是正确的,因为我从 youtube api 示例代码创建了一个新项目,并且它运行良好。
虽然从我的项目运行时我得到:
E/YouTubeAndroidPlayerAPI: Error creating YouTubePlayerView
com.google.android.youtube.player.internal.w$a: Exception thrown by invoked constructor in com.google.android.youtube.api.jar.client.RemoteEmbeddedPlayer
...
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
...
Caused by: java.lang.IllegalArgumentException: The concrete class implementing IObjectWrapper must have exactly *one* declared private field for the wrapped object. Preferably, this is an instance of the ObjectWrapper<T> class.
at zst.a(SourceFile:76)
我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textAppearance="@android:style/TextAppearance.Small"
android:gravity="center"
android:text="Youtube!"/>
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerFragment"
android:id="@+id/youtube_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
还有我的 Activity :
public class EducationVideoActivity extends YouTubeFailureRecoveryActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_education_youtube);
YouTubePlayerFragment youTubePlayerFragment =
(YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.youtube_fragment);
youTubePlayerFragment.initialize(YoutubeKey.DEVELOPER_KEY, this);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
if (!wasRestored) {
player.cueVideo("nCgQDjiotG0");
}
}
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.youtube_fragment);
}
}
我在网上尝试了其他几个示例,它们都给出了相同的错误。欢迎提出任何建议!
最佳答案
我在荣耀 8 上遇到了一些问题。
我第一次以这种方式导入 YouTubeAndroidPlayerApi.jar -> 右键单击项目中的应用程序文件夹 -> 新建 -> 模块 -> 导入 .JAR/.AAR 包 -> 选择 YouTubeAndroidPlayerApi.jar -> 完成。然后打开项目结构并在 Dependencies 选项卡中添加 Module 依赖项。在这个 gradle 完成后,在 build.gradle 中是 compile project(':YouTubeAndroidPlayerApi')
。这样就发生了创建 YouTubePlayerView 的错误。
所以我还原了所有内容并像这样导入了 lib -> 将 YouTubeAndroidPlayerApi.jar 复制到/app/libs 文件夹 -> 打开项目结构,而不是模块依赖,我选择了 Jar 依赖,并从 libs 文件夹中选择了 YouTubeAndroidPlayerApi.jar。在 gradle 完成之后,现在在 build.gradle 中是 compile files('libs/YouTubeAndroidPlayerApi.jar')
并且一切正常。
作为mike gradle中已经提到应该是compile files('libs/YouTubeAndroidPlayerApi.jar')
而不是compile project(':YouTubeAndroidPlayerApi')
。
希望对您有所帮助。
关于java - 创建 YouTubePlayerView 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42450953/
这个问题之前已经被问过here ,但我想提供更多信息。YouTubePlayerView 在滚动时通常会出现黑色轮廓,这可能会在暂停和更改旋转后发生。当我滚动并且它被覆盖时,似乎会发生这种情况,因此它
我想将 YouTube 视频与在 YouTube 应用上观看视频时显示的广告一起集成到我的应用中。 所以我想知道使用 YouTubePlayerView 是否可以解决我的问题,或者我是否必须使用 Yo
我正在使用 YouTubePlayerView 加载视频。视频播放成功,但是当屏幕旋转时,它停止播放。我该如何解决这个问题?这可能是一件简单的事情。我用谷歌搜索但没有得到帮助,但需要你的帮助.....
我在我的项目中使用了 YouTubePlayerView。但是播放视频时出现问题。 我在一些设备上测试过它, Moto lollipop (api 22) --> 显示“不幸的是 Youtube 已停
我使用以下 Activity 从我的应用程序启动了一个 YouTube 视频。启动 Activity 时,将播放 youtube 视频。但是当我改变屏幕的方向时,视频没有恢复而是从头开始。这里有什么问
我想在我的应用程序上实现 YouTube 播放器 View ,但由于我的应用程序是一个闹钟,我不希望用户能够暂停/停止视频或更改音量。我试图在 YouTube 播放器 View 上放置一个 View
是否可以在滚动 RecyclerView 时使用 Youtube API 自动播放视频? 最佳答案 是的,这是可能的。看这个例子:https://androidtutorialmagic.wordpr
我没有运气让 youtube-api 在 android 上工作。我正在努力获得最低限度的工作 - 只需通过公共(public)访问(无 oauth)播放视频。我有一个来自谷歌的 key ,我在我的模
I'm making an application that implements the picture in picture functionality in android. When you
我试图将 YouTubePlayerView 放入我的适配器中,但没有成功。 我不想调用新的 Intent。我想在我的应用程序中显示视频。 我将 YouTubeAndroidPlayerApi.jar
我想在 YouTubePlayerView 中添加一个按钮但不知道这样做的最佳方法。我希望只有当用户单击屏幕以调出 youtube 控件(播放/暂停、时间轴、共享等)时,该按钮才会出现,这些控件会在几
首先,我想指出,在 Android 中似乎存在一个限制,即在 ScrollView 上使用 SurfaceView 无法正常工作预计。这是解释here(VideoView 在内部使用了 Surface
我有一个 fragment ,它有一堆安卓 View 来播放各种媒体项目——图像、mp4 视频、pdf。 我想支持 YouTubePlayerView 以支持播放 youtube 视频。我知道使用 Y
我有一个可以以编程方式创建多个 YouTubePlayerView 的 Activity ,这是包含每个 YouTubePlayerView 的类。 public class MyYouTubeVie
我的 Activity 有一个 YouTubePlayerView,它必须显示在 SurfaceView(相机预览)上。 但是,由于 YouTubePlayerView 的视频 View 也使用了 S
我正在开发 ARKit 应用程序,我正在检测平面图并使用 YoutubePlayerView 添加 YouTube 视频 pod 浮出水面。我设法检测到表面并添加了 YouTubePlayerView
我正在使用 YouTube API,我想在全屏模式下对 YouTubePlayerView 应用 Swipe 左右手势。 当 YouTubePlayerView 处于全屏模式时,滑动 手势在 Andr
我正在尝试使用 Youtube API 将 youtube 视频嵌入到 android 应用程序中。我导入了 jar,将它添加到我的构建路径,并在我的主视图中添加了一个 YouTubePlayerVi
我正在创建一个应用程序,它将从 youtube 加载视频。我遇到的问题是我无法弄清楚如何在 android fragment 中实例化 YoutubePlayerView,因为我的应用程序只有一个 A
我正在 YouTubePlayerView(在 android 设备中)加载视频。最初它播放 2 秒,然后通过在其上显示播放按钮停止。如果我再次按下播放按钮,视频会播放 2 秒然后暂停。 最佳答案 我
我是一名优秀的程序员,十分优秀!