下面的例子顯示了如何使用視頻視圖(VideoView)類顯示從YouTube載入的視頻.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<VideoView
android:id="@+id/video"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
AndroidVideoView.java
package com.AndroidVideoView;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class AndroidVideoView extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView)findViewById(R.id.video);
String src = "rtsp://v2.cache2.c.youtube.com/CjYLENy73wIaLQm3JbT_9HqWohMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYIvJo6nmx9DvSww=/0/0/0/video.3gp";
videoView.setVideoURI(Uri.parse(src));
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
videoView.start();
}
}
注意:它不能在Android模擬器顯示, 需要運行在真的Android機.
我一直在emulator上失敗,換到device上就好了,非常感謝!~
回覆刪除請問有能夠將這種影片存檔的辦法嗎?
回覆刪除