60 likes | 163 Views
Android 線上播放 YouTuBe. 建國科技大學 資管系 饒瑞佶 2013/7 V1. Android 線上播放 YouTuBe. 主要透過 Google 提供的 class 需要 YouTuBe 的 video ID 即可 不需要 Google 服務的帳號與密碼. 加入需要的權限. < uses-permission android:name = "android.permission.INTERNET" />
E N D
Android線上播放YouTuBe 建國科技大學 資管系 饒瑞佶 2013/7 V1
Android線上播放YouTuBe • 主要透過Google提供的class • 需要YouTuBe的video ID即可 • 不需要Google服務的帳號與密碼
加入需要的權限 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
layout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:text="請輸入youtube影片編號" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/youtubeIdLabel"></TextView> <EditTextandroid:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/youtubeIdText" android:text="@string/defaultYoutubeVideoId"></EditText> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="播放影片" android:id="@+id/viewVideoButton"></Button> </LinearLayout>
onCreate() @Override protectedvoid onCreate(Bundle pSavedInstanceState) { super.onCreate(pSavedInstanceState); setContentView(R.layout.sample); // find vews final TextView videoIdTextView = (TextView) findViewById(R.id.youtubeIdText); final Button viewVideoButton = (Button) findViewById(R.id.viewVideoButton); // 設定按鈕事件 viewVideoButton.setOnClickListener(new View.OnClickListener() { @Override publicvoid onClick(View pV) { String videoId = videoIdTextView.getText().toString(); if(videoId == null || videoId.trim().equals("")){ return; } Intent lVideoIntent = new Intent(null, Uri.parse("ytv://"+videoId), Sample.this, OpenYouTubePlayerActivity.class); startActivity(lVideoIntent); } }); } 呼叫class OpenYouTubePlayerActivity
其他 Google提供