Android YouTube 应用播放视频意图 [英] Android YouTube app Play Video Intent

查看:35
本文介绍了Android YouTube 应用播放视频意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个应用程序,您可以在其中下载适用于 Android 的 YouTube 视频.现在,我想要它,如果你在 YouTube 原生应用中播放视频,你也可以下载它.为此,我需要知道 YouTube 原生应用为了播放 YouTube 应用而推出的 Intent.
如果我的模拟器上有 YouTube 程序,我可以轻松地做到这一点,所以我的第一个问题是:
1. 我可以为我的模拟器下载 YouTube 应用程序,或者...
2. 用户选择视频播放时使用的意图是什么.

I have created a app where you can download YouTube videos for android. Now, I want it so that if you play a video in the YouTube native app you can download it too. To do this, I need to know the Intent that the YouTube native app puts out in order to play the YouTube app.
I could do this easially if I had the YouTube program on my emulator, so my 1st question is:
1. Can I download the YouTube app for my emulator, or...
2. What is the intent used when the user selects a video for playback.

推荐答案

这个怎么样:

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

这篇关于Android YouTube 应用播放视频意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆