【发布时间】:2021-07-11 23:45:04
【问题描述】:
在本机 (Java) Android 应用程序中,我试图打开一个 Youtube 视频 URL。
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(formattedUrl));
context.startActivity(Intent.createChooser(intent, context.getString(R.string.show_title)));
我尝试以不同的有效方式格式化 URL,例如:
- http://www.youtube.com/watch?v=codehere
- https://www.youtube.com/watch?v=codehere
- https://youtu.be/codehere
但我总是在 Youtube 应用程序中收到“此视频不可用”错误消息。任何版本的链接都可以在浏览器中查看。该应用程序最近一次更新是在几年前(之前运行没有任何问题),所以也许 Youtube 有一些我不知道的限制?
如果可能的话,我希望通过 Intent 和 URL 继续打开视频,并且不安装任何其他库。
更新!
我尝试使用 YouTubeStandalonePlayer 库,但得到了相同的结果:
if (isYoutubeVideo) {
final String youtubeApiKey = Prefs.getString(ConfigDumpService.CMS_CONFIG.YOUTUBE_PLAYER_API_KEY);
final String videoId = Strings.extractVideoIdFromUrl(formattedUrl);
context.startActivity(YouTubeStandalonePlayer.createVideoIntent((Activity)context, "my-key-here", videoId));
}
泰!
【问题讨论】:
标签: android android-intent youtube