从URL -Android播放视频

时间:2011-06-25 07:00:24

标签: android

在下面的代码中,视频dosnt似乎在这里玩错了。这是权限问题,如果是的话应该包含在清单文件中 这个 的 main.xml中

 <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:baselineAligned="true">
         <LinearLayout android:layout_height="match_parent" android:layout_width="wrap_content" android:id="@+id/linearLayout2"></LinearLayout>
         <MediaController android:id="@+id/mediacnt" android:layout_width="wrap_content" android:layout_height="wrap_content"></MediaController>
         <LinearLayout android:layout_height="match_parent" android:layout_width="wrap_content" android:id="@+id/linearLayout1" android:orientation="vertical"></LinearLayout>
         <Gallery android:layout_height="wrap_content" android:id="@+id/gallery" android:layout_width="wrap_content" android:layout_weight="1"></Gallery>
         <VideoView android:layout_height="match_parent" android:id="@+id/vv" android:layout_width="wrap_content"></VideoView>

     </LinearLayout>

这是 java class

 package com.gallery;
     import java.net.URL;

     import android.app.Activity;

     import android.app.Activity;
     import android.net.Uri;
     import android.os.Bundle;
     import android.widget.MediaController;
     import android.widget.Toast;
     import android.widget.VideoView;

     public class GalleryActivity extends Activity {
         /** Called when the activity is first created. */
         @Override
         public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Toast.makeText(GalleryActivity.this, "Hello world", Toast.LENGTH_LONG).show();
        VideoView videoView = (VideoView) findViewById(R.id.vv);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
     // Set video link (mp4 format )
        Uri video = Uri.parse("http://www.youtube.com/watch?v=lEbxLDuecHU&playnext=1&list=PL040F3034C69B1674");
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.start();


         }
     }

2 个答案:

答案 0 :(得分:0)

将Internet权限添加到应用程序的清单文件

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

此链接您应该AndroidVideoComponent这也是MediaPlayerDemo_Video

答案 1 :(得分:-1)

如果您想在wifi状态下播放来自URL的视频,您需要在清单文件中添加wifi和网络状态权限,如下所示:

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