Android

视频播放器

2020-05-27  本文已影响0人  夜沐下的星雨

视频播放器:

使用系统自带的播放器

Uri parse = Uri.parse(data);//显示数据给用户

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setDataAndType(parse,"video/mp4");

startActivity(intent); 

使用VideoView结合MediaController来播放视频

```

<VideoView

    android:id="@+id/video_view"

    android:layout_width="match_parent"

    android:layout_height="200dp" />

public void playVideoView() {

        String mp4path = Environment.getExternalStorageDirectory() + File.separator + "xxx.mp4";

        mVideoView.setVideoURI(Uri.parse(mp4path));

        mVideoView.start();

        mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

            @Override

            public void onCompletion(MediaPlayer mp) {

                Log.d(TAG, "onCompletion: ");

            }

        });

    }

```

饺子播放器:

1.依赖

implementation 'cn.jzvd:jiaozivideoplayer:6.2.9'

```

<cn.jzvd.JZVideoPlayerStandard

    android:id="@+id/videoplayer"

    android:layout_width="match_parent"

    android:layout_height="200dp" />

```

2.简单使用

```

public void jiaoziPlayer(){

    String mp4path = Environment.getExternalStorageDirectory() + File.separator + "xxx.mp4";

    JZVideoPlayerStandard jzVideoPlayerStandard = (JZVideoPlayerStandard) findViewById(R.id.videoplayer);

    jzVideoPlayerStandard.setUp(mp4path

         , JZVideoPlayerStandard.SCREEN_WINDOW_NORMAL, "饺子闭眼睛");

    jzVideoPlayerStandard.thumbImageView.setImageResource(R.drawable.ic_launcher_background);

```

上一篇 下一篇

猜你喜欢

热点阅读