我開發了自己的媒體播放器,我希望當我想從Youtube上觀看視頻時,它應該從我的應用程序打開。至少,視圖上應該有一個媒體應用列表,我應該可以從列表中選擇我的應用。我對意圖過濾器知之甚少。我怎樣才能在我的清單文件中提供這個?我正在努力爲本地文件進行培訓,但我還沒有做到。我真的需要你的幫助:/媒體播放器的意圖過濾器(Youtube視頻播放)
4
A
回答
11
如果你看看意圖過濾器的官方YouTube應用程式使用,您將看到:
<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>
2
我正在更新H9kDroid的答案,這是2011年的答案。這些是來自當前(2015年1月11日)最新YouTube APK的相關反編譯意圖過濾器。
<activity-alias android:theme="@01030055"
android:name="com.google.android.youtube.UrlActivity"
android:exported="true"
android:targetActivity="com.google.android.apps.youtube.app.honeycomb.Shell$UrlActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW">
</action>
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH">
</action>
<action android:name="android.nfc.action.NDEF_DISCOVERED">
</action>
<category android:name="android.intent.category.DEFAULT">
</category>
<category android:name="android.intent.category.BROWSABLE">
</category>
<data android:scheme="http">
</data>
<data android:scheme="https">
</data>
<data android:host="youtube.com">
</data>
<data android:host="www.youtube.com">
</data>
<data android:host="m.youtube.com">
</data>
<data android:host="youtu.be">
</data>
<data android:pathPattern=".*">
</data>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW">
</action>
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH">
</action>
<action android:name="android.nfc.action.NDEF_DISCOVERED">
</action>
<category android:name="android.intent.category.DEFAULT">
</category>
<category android:name="android.intent.category.BROWSABLE">
</category>
<data android:scheme="vnd.youtube">
</data>
<data android:scheme="vnd.youtube.launch">
</data>
</intent-filter>
</activity-alias>
這就是這些意圖是如何在代碼中被解析的。對不起,這是混淆,但在我的情況仍然有用:
import android.net.Uri;
import android.net.Uri.Builder;
import android.text.TextUtils;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public final class glb
{
public final List a;
public final int b;
private glb(String paramString, Map paramMap, int paramInt)
{
this(Collections.singletonList(paramString), paramMap, paramInt);
}
private glb(List paramList, Map paramMap, int paramInt)
{
this.a = Collections.unmodifiableList((List)b.c(paramList, "videoIds can not be null"));
if (!this.a.isEmpty()) {}
for (boolean bool = true;; bool = false)
{
b.c(bool, "videoIds cannot be empty");
Collections.unmodifiableMap((Map)b.c(paramMap, "params can not be null"));
this.b = paramInt;
return;
}
}
private static int a(Uri paramUri, Map paramMap)
{
String str1 = (String)paramMap.get("t");
if (str1 == null)
{
String str2 = Uri.decode(paramUri.getEncodedFragment());
if (!TextUtils.isEmpty(str2))
{
String[] arrayOfString1 = str2.split("&");
int i = arrayOfString1.length;
for (int j = 0; j < i; j++)
{
String[] arrayOfString2 = arrayOfString1[j].split("=");
if ((arrayOfString2.length == 2) && ("t".equals(arrayOfString2[0]))) {
str1 = arrayOfString2[1];
}
}
}
}
return a(str1);
}
private static int a(String paramString)
{
if (paramString == null) {
return 0;
}
int i = paramString.indexOf("h");
int j;
if (i >= 0)
{
j = 0 + 3600000 * a.b(paramString.substring(0, i), 0);
paramString = paramString.substring(i + 1);
}
for (;;)
{
int k = paramString.indexOf("m");
if (k >= 0)
{
j += 60000 * a.b(paramString.substring(0, k), 0);
paramString = paramString.substring(k + 1);
}
if (paramString.endsWith("s")) {
paramString = paramString.substring(0, -1 + paramString.length());
}
return j + (int)(1000.0F * a.a(paramString, 0.0F));
j = 0;
}
}
public static glb a(Uri paramUri)
{
if ("https".equals(paramUri.getScheme())) {
paramUri = paramUri.buildUpon().scheme("http").build();
}
if ("vnd.youtube".equals(paramUri.getScheme()))
{
String str7 = paramUri.getSchemeSpecificPart();
if (str7.startsWith("//")) {
str7 = str7.substring(2);
}
if (TextUtils.isEmpty(str7))
{
String str9 = String.valueOf(paramUri);
throw new ParseException(24 + String.valueOf(str9).length() + "No video id in the Uri: " + str9, 0);
}
int i = str7.indexOf('?');
if (i > 0) {}
for (String str8 = str7.substring(0, i);; str8 = str7)
{
Map localMap3 = b(paramUri);
return new glb(str8, localMap3, a((String)localMap3.get("t")));
}
}
if ("youtu.be".equalsIgnoreCase(paramUri.getHost()))
{
List localList = paramUri.getPathSegments();
if ((localList.isEmpty()) || (TextUtils.isEmpty((CharSequence)localList.get(0))))
{
String str6 = String.valueOf(paramUri);
throw new ParseException(29 + String.valueOf(str6).length() + "No video id in the Uri path: " + str6, 0);
}
Map localMap2 = b(paramUri);
return new glb(localList.subList(0, 1), a(localMap2), a(paramUri, localMap2));
}
String str1 = paramUri.getPath();
String str2 = paramUri.getFragment();
if ((str1.startsWith("/watch")) || (str1.startsWith("/movie"))) {
return c(paramUri);
}
if (str1.startsWith("/get_video"))
{
Map localMap1 = b(paramUri);
String str4 = (String)localMap1.get("video_id");
if (!TextUtils.isEmpty(str4)) {
return new glb(str4, a(localMap1), a(paramUri, localMap1));
}
String str5 = String.valueOf(paramUri);
throw new ParseException(24 + String.valueOf(str5).length() + "No id found in the uri: " + str5, 0);
}
if (str1.startsWith("/v/")) {
return d(paramUri);
}
if ((str1.startsWith("/e/")) || (str1.startsWith("/embed/"))) {
return new glb(paramUri.getLastPathSegment(), b(paramUri), a(paramUri.getQueryParameter("start")));
}
if ((str2 != null) && ((str2.startsWith("/watch")) || (str2.startsWith("watch"))))
{
String str3 = paramUri.getFragment();
return c(Uri.parse(paramUri.buildUpon().encodedPath(str3).fragment("").build().toString()));
}
throw new ParseException("Unrecognised URI", 0);
}
private static Map a(Map paramMap)
{
HashMap localHashMap = new HashMap(paramMap);
localHashMap.remove("v");
localHashMap.remove("video_id");
localHashMap.remove("video_ids");
localHashMap.remove("feature");
return localHashMap;
}
private static Map b(Uri paramUri)
{
if (paramUri.isOpaque()) {
return Collections.emptyMap();
}
HashMap localHashMap = new HashMap();
Iterator localIterator = paramUri.getQueryParameterNames().iterator();
while (localIterator.hasNext())
{
String str = (String)localIterator.next();
localHashMap.put(str, paramUri.getQueryParameter(str));
}
return localHashMap;
}
private static glb c(Uri paramUri)
{
Map localMap = b(paramUri);
String str1 = (String)localMap.get("v");
String str2 = (String)localMap.get("video_ids");
if ((TextUtils.isEmpty(str1)) && (TextUtils.isEmpty(str2)))
{
List localList = paramUri.getPathSegments();
int i = localList.indexOf("watch");
if (i < 0)
{
String str6 = String.valueOf(paramUri);
throw new ParseException(28 + String.valueOf(str6).length() + "No /watch/ part in the Uri: " + str6, 0);
}
if (i + 1 >= localList.size())
{
String str5 = String.valueOf(paramUri);
throw new ParseException(24 + String.valueOf(str5).length() + "No id found in the Uri: " + str5, 0);
}
str1 = (String)localList.get(i + 1);
if (TextUtils.isEmpty(str1))
{
String str4 = String.valueOf(paramUri);
throw new ParseException(24 + String.valueOf(str4).length() + "No video id in the Uri: " + str4, 0);
}
}
String str3 = str1;
if (str2 == null) {
return new glb(str3, a(localMap), a(paramUri, localMap));
}
return new glb(Arrays.asList(str2.split(",")), a(localMap), a(paramUri, localMap));
}
private static glb d(Uri paramUri)
{
String[] arrayOfString1 = paramUri.getLastPathSegment().split("&");
String str = arrayOfString1[0];
HashMap localHashMap = new HashMap();
for (int i = 1; i < arrayOfString1.length; i++)
{
String[] arrayOfString2 = arrayOfString1[i].split("=");
if (arrayOfString2.length == 2) {
localHashMap.put(arrayOfString2[0], arrayOfString2[1]);
}
}
return new glb(str, localHashMap, a((String)localHashMap.get("start")));
}
}
相關問題
- 1. 如何使用YouTube視頻更改媒體播放器和媒體播放器?
- 2. 在kaltura播放Youtube視頻播放器
- 3. 媒體播放器同步播放音頻和視頻android
- 4. 沒有視頻媒體播放器
- 5. 流媒體視頻播放器
- 6. 流媒體視頻播放器
- 7. Youtube播放器Iframe API跳過播放列表中的視頻
- 8. 如何在YouTube視頻播放器中播放YouTube視頻中的視頻android
- 9. 安卓視頻不能播放媒體播放器
- 10. 在媒體播放器黑莓中播放視頻
- 11. 如何在同一頁面播放視頻(媒體播放器)
- 12. 媒體元素Js視頻播放器無法正常播放
- 13. 不使用媒體播放器播放視頻
- 14. 如何在wpf媒體播放器中播放視頻?
- 15. 使用YouTube播放器API播放不同的YouTube視頻
- 16. 使用Uri通過媒體播放器播放音頻剪輯
- 17. 通過意向播放youtube視頻
- 18. 如何通過YouTube播放器自動播放視頻
- 19. 類似於YouTube播放器的視頻播放器建議
- 20. android中的浮動視頻播放器(如youtube播放器)
- 21. 帶有播放列表的YouTube頻道視頻播放器
- 22. Android - 在ListView中使用YouTube播放器API播放Youtube視頻
- 23. Youtube HTML5視頻播放器播放器API後退(v2)
- 24. Android媒體播放器不播放
- 25. 媒體播放器播放兩次
- 26. 媒體播放器和延遲播放
- 27. 媒體播放器無法播放onActivityResult
- 28. 媒體播放器MOV播放失敗
- 29. 媒體播放器不能播放
- 30. YouTube播放器的視頻不加載
wheew終於找到了它謝謝我的傢伙 – fullMoon 2016-01-30 10:49:11