我想通過視頻網址將YouTube視頻嵌入到我的Android活動中。這是我迄今所做的:活動中的視頻流
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
import android.app.Activity;
public class MainActivity extends Activity {
String videoUrl= "http://www.youtube.com/watch?v=oSD0YigRW3o";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.videoview);
//Use a media controller so that you can scroll the video contents
//and also to pause, start the video.
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse(videoUrl));
videoView.start();
} }
,這是我的.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Video Test.."
android:textAppearance="?android:attr/textAppearanceLarge" />
<VideoView
android:id="@+id/videoview"
android:layout_width="fill_parent"
android:layout_height="161dp"
android:layout_weight="0.34" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Video Test.."
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
有除了在設備上說,當應用程序運行Sorry, this video cannot be played
我該如何解決沒有錯誤這個問題?謝謝。
注:如果我可以將視頻與移動播放器關聯起來,那也可以接受。但是,我不想在WebView中打開新的瀏覽器或選項卡。
這是我已經。並不成功。 – Umitk