<?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="horizontal" > <Button android:id="@+id/but" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="点击调取系统的播放器进行播放视频" android:onClick="setdata" /> </LinearLayout>
import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.VideoView; import com.bwie.zhoujianhang.quarter.R; /** * Created by 杨运泽. */ public class BenDiFragment extends Fragment { private View view; private Button btn; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.bendifragment, null); initViews(); return view; } //点击调取播放器进行播放视频 public void initViews(){ btn = view.findViewById(R.id.but); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //打开系统的播放器 Action Intent.ACTION_VIEW 打开系统播放器的指令 Intent intent = new Intent(Intent.ACTION_VIEW); //得到sdcard下的视频 //Environment.getExternalStorageDirectory() 得到sdcard的根目录 Uri data = Uri.parse(Environment.getExternalStorageDirectory()+"/minion_09.mp4"); //交给intent进行加载播放 设置类型 1. 视频 2.类型 intent.setDataAndType(data,"video/*"); //播放 startActivity(intent); } }); } public static BenDiFragment create(String title) { Bundle bundle = new Bundle(); bundle.putString("title", title); BenDiFragment benDiFragment = new BenDiFragment(); benDiFragment.setArguments(bundle); return benDiFragment; } }