gpt4 book ai didi

java - 优化在android上运行youtube视频的方式

转载 作者:行者123 更新时间:2023-12-01 12:48:05 24 4
gpt4 key购买 nike

我们可以有任何优化方式来运行视频。下面提到的是我的代码。此代码有助于运行 youtube 视频。

if (YouTubeIntents.canResolvePlayVideoIntent(activity)){
//Getting ID of YouTube video out of URL
List<NameValuePair> params = null;
try {
params = URLEncodedUtils.parse(new URI(sourceUrl), "UTF-8");

} catch (URISyntaxException e) {

e.printStackTrace();
}
String videoID = params.get(0).getValue();
Log.v(TAG, "YouTube Video ID:" + videoID);
// createPlayVideoIntentWithOptions only works for first
// video playback. Update to use stand-alone player api instead.

Intent intent = YouTubeStandalonePlayer.createVideoIntent(
activity, g.kGoogleAPIKey,
videoID, 0, true, false);
activity.startActivity(intent);
Log.i(TAG, "Video Playing in YouTube App....");
} else {
Log.v(TAG, "YouTube generic intent");
activity.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(sourceUrl)));
Log.i(TAG, "Video Playing in whatever user selected....");
}

最佳答案

你的问题有点模糊..如果你只想从你的应用程序播放youtube视频,你可以轻松地调用youtube Intent ..并传递视频的url作为额外的。这将打开 youTube..

或者,您可以访问 youTube Player api:https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/package-summary

您必须获取 api key 并执行如下操作:

此示例旨在查看您的用户是否可以使用独立播放器,以及是否如我的答案第一部分所述直接调用 YouTube

  if (YouTubeIntents.canResolvePlayVideoIntent(activity)){
//Getting ID of YouTube video out of URL
List<NameValuePair> params = null;
try {
params = URLEncodedUtils.parse(new URI(sourceUrl), "UTF-8");

} catch (URISyntaxException e) {

e.printStackTrace();
}
String videoID = params.get(0).getValue();
Log.v(TAG, "YouTube Video ID:" + videoID);
// createPlayVideoIntentWithOptions only works for first
// video playback. Update to use stand-alone player api instead.

Intent intent = YouTubeStandalonePlayer.createVideoIntent(
activity, g.kGoogleAPIKey,
videoID, 0, true, false);
activity.startActivity(intent);
Log.i(TAG, "Video Playing in YouTube App....");
} else {
Log.v(TAG, "YouTube generic intent");
activity.startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(sourceUrl)));
Log.i(TAG, "Video Playing in whatever user selected....");
}

关于java - 优化在android上运行youtube视频的方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24490554/

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