How can I enable users to play video using my app?

守給你的承諾、 提交于 2019-12-06 06:31:48

问题


Just spent a couple of hours last night developing a pretty sweet video player for Honeycomb, and now I'd of course love for people to be able to use it.

How can I make my application listen for / receive "video play broadcasts"?

I'm guessing it's got something to do with the manifest.xml file, but I was unable to find anything about it on the Android Developer site.

I've tried using the following without much success:

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

回答1:


I eventually solved this one myself with the following code in my manifest.xml file:

    <!-- 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>



回答2:


Video players are usually implemented as activities. Hence, you would use an <activity> element for that action and MIME type, not a <receiver> element. You might also want to specify both the DEFAULT and BROWSABLE categories -- the latter would be needed for links clicked on in a Web browser.



来源:https://stackoverflow.com/questions/7370875/how-can-i-enable-users-to-play-video-using-my-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!