Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent Filter for Media Player ( Youtube Video Play)

I have developed my own media player and I want that when I want to watch a video from Youtube, it shall be opened from my app. At least, there should be a list of media apps on the view and I should be able to choose my app from the list. I don't know much about intent-filters. How can I provide this in my manifest file? I am working for to make it for local files to train but I haven't been able to make it yet, too. I really need your help :/

like image 657
sjor Avatar asked Dec 10 '22 12:12

sjor


1 Answers

If you look at the intent filter the official youtube app uses you will see this:

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

To get the video ID you can parse the string you get from:

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

As you can see there is no filter for youtu.be but that can be added with:

<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>
like image 51
H9kDroid Avatar answered Dec 29 '22 02:12

H9kDroid