1

我正在开发一个学校应用程序,我想从我的 PHP 服务器播放视频

我试过这段代码,但它无法播放

Uri video = Uri.fromFile(myurl); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); intent.setDataAndType(video, "video/*");

4

2 回答 2

2

try this one, play the video on vedio view through the parse the uri

xml part

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <VideoView
        android:id="@+id/surface_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        />
</FrameLayout>

Now java part

 public class HelloInterruptVideoStream extends Activity
{
    private String path = "http://dl.dropbox.com/u/145894/t/rabbits.3gp";
    private VideoView videoview;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        videoview = (VideoView)findViewById(R.id.surface_view);

        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
           getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        videoview.setVideoURI(Uri.parse(path));
        videoview.setMediaController(new MediaController(this));
        videoview.requestFocus();
        videoview.start();
    }
}

Use internet permission in menifest file

<uses-permission android:name="android.permission.INTERNET"/>
于 2013-06-11T06:07:43.933 回答
0

尝试以MediaController这种方式设置您的:

MediaController mediaController= new MediaController(this);

mediaController.setAnchorView(video);  
videoview.setMediaController(mediaController);
于 2016-12-07T13:02:10.050 回答