【问题标题】:Open youtube video at a specific time using android intent使用 android 意图在特定时间打开 youtube 视频
【发布时间】:2017-06-01 12:06:37
【问题描述】:

我正在从我的应用中打开一个 youtube 视频,与此答案类似:https://stackoverflow.com/a/12439378/379865

我想知道是否可以在指定时间打开视频,例如让视频从 30 秒开始播放,而不是从头开始播放。

【问题讨论】:

  • 我认为当您在特定时间分享 Youtube 视频时,链接会发生变化,因此您可能需要相应地更改视频的链接。

标签: android android-intent


【解决方案1】:

YouTube 有一种很好的方式在视频的 URL 中指示时间。

Intent 看起来像 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=Z149x12sXs" + time))); 其中String time = "&t=0m30s";

编辑:YouTube 应用扩展。

public static void watchYoutubeVideo(String id, String time){
    Intent appIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + id + time));
    Intent webIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://www.youtube.com/watch?v=" + id + time));
    try {
        startActivity(appIntent);
    } catch (ActivityNotFoundException ex) {
        startActivity(webIntent);
    }
} 

使用该问题的另一个答案。相同的逻辑可以应用于任何意图,只需将Time 字符串添加到URI,如上所示,无论意图如何。

【讨论】:

  • 这在浏览器中启动视频时有效。我需要在使用 YT 应用程序时进行测试。谢谢
  • 对我来说,在 android 5 上使用 vnd.youtube 方式不起作用。它会打开 youtube 应用程序,但无法加载视频。但是,使用 webIntent 打开仍然有效,即使从菜单中选择使用 YouTube 应用打开也是如此。
【解决方案2】:

尝试使用类似于此的 url 打开 url https://www.youtube.com/watch?v=u0IU8uQniX8&t=2m35s

其中 t= 以分钟和秒为单位的时间

t=2m35s

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-15
    • 1970-01-01
    • 2019-07-15
    • 2010-10-09
    • 2018-09-17
    • 2018-08-12
    • 1970-01-01
    相关资源
    最近更新 更多