【发布时间】:2019-08-01 09:26:53
【问题描述】:
我正在编写一个应用程序,并希望该应用程序使用 YouTube API 播放 YouTube 视频。我在 YouTubeStandalonePlayer.createVideoIntent (context, YTapiKey, videoID) 的 context 参数中放了什么?
文档说上下文应该是一个活动。我试过 MainActivity、activity_main 和 findViewById(R.layout.activity_main)。它们都不起作用。
MainActivity.kt 文件:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val intent = YouTubeStandalonePlayer.createVideoIntent(context, YTapiKey, videoID)
startActivity(intent)
}
}
activity_main.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.vcsw.explicacao.MainActivity">
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtubePlayerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
我希望简单地将活动的名称放在意图的上下文参数中 YouTubeStandalonePlayer.createVideoIntent(context, YTapiKey, videoID) 会起作用,但它没有。
【问题讨论】:
-
上下文使用
this
标签: android kotlin youtube-api