简单的调用本地服务器播放网络视频

来源:互联网 发布:美图秀秀软件旧版本 编辑:程序博客网 时间:2024/05/16 12:09

下抿的

xml文件布局:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    >    <Button       android:text="播放网络视频"        android:id="@+id/button"        android:layout_width="fill_parent"        android:layout_height="40dp"        android:layout_alignParentEnd="true" /></RelativeLayout>

mainactivity代码:

package com.example.play;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.widget.Button;public class MainActivity extends Activity implements View.OnClickListener {    private Button button;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        button = (Button) findViewById(R.id.button);        button.setOnClickListener(this);    }    @Override    public void onClick(View v) {        int id = v.getId();        switch(id){            case R.id.button:            {                String url = "http://dvideo.spriteapp.cn/video/2016/0307/56dd1c633f680_wpd.mp4";               //这个地址很重要就是你要播放的网络视频的地址                Uri uri = Uri.parse(url);                Intent intent = new Intent(Intent.ACTION_VIEW,uri);                intent.setType("video/*");                intent.setDataAndType(uri , "video/*");                startActivity(intent);                break;            }        }    }}

0 0
原创粉丝点击