Android 線上播放 YouTuBe

6
Android 線線線線 YouTuBe 線線線線線線 線線線 線線線 2013/7 V1

description

Android 線上播放 YouTuBe. 建國科技大學 資管系 饒瑞佶 2013/7 V1. Android 線上播放 YouTuBe. 主要透過 Google 提供的 class 需要 YouTuBe 的 video ID 即可 不需要 Google 服務的帳號與密碼. 加入需要的權限. < uses-permission android:name = "android.permission.INTERNET" /> - PowerPoint PPT Presentation

Transcript of Android 線上播放 YouTuBe

Page 1: Android 線上播放 YouTuBe

Android 線上播放 YouTuBe

建國科技大學 資管系饒瑞佶

2013/7 V1

Page 2: Android 線上播放 YouTuBe

Android 線上播放 YouTuBe

• 主要透過 Google 提供的 class• 需要 YouTuBe 的 video ID 即可• 不需要 Google 服務的帳號與密碼

Page 3: Android 線上播放 YouTuBe

加入需要的權限

<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Page 4: Android 線上播放 YouTuBe

layout<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns: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> <EditText android: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>

Page 5: Android 線上播放 YouTuBe

@Override protected void 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 public void 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); } }); }

onCreate()

呼叫 classOpenYouTubePlayerActivity

Page 6: Android 線上播放 YouTuBe

其他

Google 提供