java - 媒体播放器的 Intent 过滤器(Youtube 视频播放)

标签 java android youtube android-intent media

我开发了自己的媒体播放器,我希望当我想从 Youtube 观看视频时,它应该从我的应用程序中打开。至少, View 上应该有一个媒体应用程序列表,我应该能够从列表中选择我的应用程序。我对 Intent 过滤器了解不多。我如何在我的 list 文件中提供这个?我正在努力为本地文件进行训练,但我也还没能做到。我真的需要你的帮助:/

最佳答案

如果您查看官方 youtube 应用程序使用的 intent 过滤器,您会看到:

<activity android:name="Player">

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http"  android:host="youtube.com" android:pathPrefix="/watch" />
        <data android:scheme="https" android:host="youtube.com" android:pathPrefix="/watch" />
    </intent-filter>

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http"  android:host="*.youtube.com" android:pathPrefix="/watch" />
        <data android:scheme="https" android:host="*.youtube.com" android:pathPrefix="/watch" />
    </intent-filter>

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http"  android:host="www.youtube.com" android:pathPrefix="/v/" />
        <data android:scheme="https" android:host="www.youtube.com" android:pathPrefix="/v/" />
        <data android:scheme="http"  android:host="www.youtube.com" android:pathPrefix="/e/" />
        <data android:scheme="https" android:host="www.youtube.com" android:pathPrefix="/e/" />
        <data android:scheme="http"  android:host="www.youtube.com" android:pathPrefix="/embed/" />
        <data android:scheme="https" android:host="www.youtube.com" android:pathPrefix="/embed/" />
    </intent-filter>

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="vnd.youtube" />
    </intent-filter>

</activity>

要获取视频 ID,您可以解析从中获取的字符串:

Uri uri = this.getIntent().getData();

如您所见,youtu.be 没有过滤器,但可以添加:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http"  android:host="youtu.be" />
    <data android:scheme="https" android:host="youtu.be" />
</intent-filter>

关于java - 媒体播放器的 Intent 过滤器(Youtube 视频播放),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4487867/

相关文章:

java - 如何以编程方式在异步任务中等待android(java)中的wifi连接(接入点)?

android - Honeycomb 启用硬件加速时支持哪些 API?

Android 使用适当的应用程序列表启动应用程序选择器

java - Android GPS 起初工作,但后来返回空值

android - 需要使用YouTube API授权Android应用的指南

java - 当我的当前位置在 2 个或更多圆圈内时,如何在 google maps android 中获取到圆圈外最短路径的方向?

java - 维护不同表单提交之间的状态

ios - 从 iOS 应用程序打开 youtube channel 的最新 URL 方案是什么

youtube - RTSP流无法在诺基亚40系列手机中使用

java - 如何找到与象限无关的点与x轴的角度?