如上所述previously您可以與開放的youtube播放器播放youtube視頻。
我附上了工作樣本here。 (驅動器是我心中最好的解決方案,你可以按ctrl + s保存rar文件)。在那裏你會找到兩個項目。
- YouTubeTester - 示例應用程序我已經做了
- OpenYouTubeActivity - 即下載的形式here
YouTube播放器我已經包括OpenYouTubeActivity項目的jar文件到我的項目,如果你喜歡你可以將OpenYouTubeActivity項目作爲項目庫引用(如果將項目作爲庫引用,請確保刪除該jar文件)。 OpenYouTubeActivity的下載源已發行list
VideoStream.java (Line: 30)
change: mUrl = lArgMap.get("url");
to: mUrl = lArgMap.get("url") + "&signature=" + lArgMap.get("sig");
現在回到示例項目更新提。
清單文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.youtubetester"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<!--INTERNET and ACCESS_WIFI_STATE permissions are required. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".YouTubeTest"
android:label="@string/title_activity_you_tube_test" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- You should include following part orientation is your choice-->
<activity
android:name="com.keyes.youtube.OpenYouTubePlayerActivity"
android:screenOrientation="landscape" >
</activity>
</application>
</manifest>
YouTubeTest活動類
package com.youtubetester;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.keyes.youtube.OpenYouTubePlayerActivity;
public class YouTubeTest extends Activity {
private Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_you_tube_test);
button =(Button) findViewById(R.id.play);
/*
* The Youtube URL that we get is something like following.
* http://www.youtube.com/watch?v=J467jzLlDcc
* We need the last part of the URL or id of the video-J467jzLlDcc **/
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent lVideoIntent = new Intent(null, Uri
.parse("ytv://"+"J467jzLlDcc"),
YouTubeTest.this,
OpenYouTubePlayerActivity.class);
startActivity(lVideoIntent);
/*
* Please note only the id has been passed and prefix is "ytv" NOT "ytpl"*/
}
});
}
}
佈局 - activity_you_tube_test.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".YouTubeTest" />
</RelativeLayout>
希望這會有所幫助。請詢問你是否有任何問題。我對OpenYouTubeActivity項目沒有深入的瞭解,但我可以提供幫助。
你首先從視頻的youtube網址中提取視頻ID,然後你可以播放它。 –
我認爲youtube webservice提供了rstp links.Android 4.0.4支持RSTP鏈接。 – AppMobiGurmeet
任何人都可以提供我的工作示例 – user1551578