美文网首页
Android 实现简单的视频播放

Android 实现简单的视频播放

作者: 年少懵懂丶流年梦 | 来源:发表于2019-01-19 16:13 被阅读3次
    <VideoView
        android:id="@+id/videoView"
        android:layout_width="match_parent"
        android:layout_height="251dp"
        android:layout_gravity="center_horizontal"
    />
    
    // 加载视屏
    String videoUrl = "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?" +
                    "filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023" +
                    "&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400";
    Uri uri = Uri.parse(videoUrl);
    VideoView videoView = this.findViewById(R.id.videoView);
    //设置视频控制器
    videoView.setMediaController(new MediaController(this));
    //播放完成回调
    videoView.setOnCompletionListener(new MyPlayerOnCompletionListener());
    //设置视频路径
    videoView.setVideoURI(uri);
    //开始播放视频
    Button button6 = findViewById(R.id.button6);
    button6.setOnClickListener(view -> {
        videoView.start();
    });
    
    class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener {
        @Override
        public void onCompletion(MediaPlayer mp) {
            Toast.makeText( LocalVideoActivity.this, "播放完成了", Toast.LENGTH_SHORT).show();
        }
    }
    

    相关文章

      网友评论

          本文标题:Android 实现简单的视频播放

          本文链接:https://www.haomeiwen.com/subject/wxlzdqtx.html