デバイスでビデオを再生しようとすると、コードを使用してAndroidアプリケーションでYouTubeビデオを再生し
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(youtube_video_url)));
ています.インターネットとYouTubeのオプションで「完全なアクションを使用して」ダイアログボックスがポップアップします. このポップアップを防ぎ、YouTube ビデオを YouTube プレーヤーで直接開くにはどうすればよいですか。さらに、Engadget のように、YouTube の動画をビデオ プレーヤーで (YouTube プレーヤーを避けて) 直接再生する方法はありますか。
4485 次
1 に答える
0
これがあなたWatchActivity
が呼び出したいものです
<activity android:name="WatchActivity" android:screenOrientation="sensor" android:configChanges="keyboardHidden|orientation" android:allowTaskReparenting="true">
<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="/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/" />
</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="/e/" />
</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>
これはデフォルトのアクティビティではありません。つまり、直接呼び出すには、次のコードを試す必要があります
String youtubePackage = "com.google.android.youtube";
ArrayList<IntentFilter> intentFilters = new ArrayList<IntentFilter>();
/*
* Filter to match
<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="/watch" />
</intent-filter>
*/
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_VIEW);
filter.addCategory(Intent.CATEGORY_DEFAULT);
filter.addCategory(Intent.CATEGORY_BROWSABLE);
//filter.addDataScheme("http");
//filter.addDataAuthority("www.youtube.com", null);//port null will allow any port
//filter.addDataPath("/watch", PatternMatcher.PATTERN_PREFIX);
intentFilters.add(filter);
ArrayList<ComponentName> outActivities = new ArrayList<ComponentName>();
getPackageManager().getPreferredActivities(intentFilters, outActivities, youtubePackage);
最後の呼び出しの後、outActivities
変数は一致するアクティビティ (ほとんどの場合 1 つだけ) を保持します。実際のところ、私には何も返されません。
何Activity
が一致するかを確認Intent
するには、パッケージを照会できます
Intent videoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.youtube.com/watch?v=EUXnJraKM3k"));
List<ResolveInfo> matchingActivities = getPackageManager().queryIntentActivities(videoIntent, PackageManager.MATCH_DEFAULT_ONLY);
または、その長い手順をすべて捨てて、そのまま使用します
Intent videoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:<video id>"));
startActivity(videoIntent);
vnd.youtube
WatchActivity
ご覧のとおり、フィルターによって受け入れられるスキームです。
于 2011-08-03T12:18:42.840 に答える