如何让用户使用我的应用程序播放视频?

时间:2011-09-10 09:37:22

标签: android video android-3.0-honeycomb

昨晚花了几个小时为Honeycomb开发了一款非常甜美的视频播放器,现在我当然喜欢能够使用它的人。

如何让我的应用程序收听/接收“视频播放广播”?

我猜这与manifest.xml文件有关,但我无法在Android开发者网站上找到任何相关信息。

我尝试使用以下内容但没有取得多大成功:

<receiver android:name=".VideoPlayer">
    <intent-filter>
        <action android:name="android.intent.action.VIEW">
            <data android:mimeType="video/*" />
        </action>
    </intent-filter>
</receiver>

2 个答案:

答案 0 :(得分:7)

我最终在我的manifest.xml文件中使用以下代码解决了这个问题:

    <!-- Video player -->
    <activity android:name=".VideoPlayer" android:label="@string/app_name"
        android:theme="@style/BlackHolo" android:screenOrientation="sensorLandscape">
        <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="rtsp" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="video/*" />
            <data android:mimeType="application/sdp" />
        </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" />
            <data android:mimeType="video/*" />
        </intent-filter>
    </activity>

答案 1 :(得分:1)

视频播放器通常用作活动。因此,您将对该操作和MIME类型使用<activity>元素,而不是<receiver>元素。您可能还需要同时指定DEFAULTBROWSABLE类别 - 在Web浏览器中单击的链接需要后者。