需求:广告url播放
解决:videoView
步骤:
布局
<VideoView android:id="@+id/video" android:layout_width="match_parent" android:layout_height="wrap_content" />
代码
//将路径转换成uri Uri uri = Uri.parse("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"); //为视频播放器设置视频路径 vv.setVideoURI(uri); //显示控制栏(无法快进) //vv.setMediaController(new MediaController(MainActivity.this)); //播放完成回调 vv.setOnCompletionListener(new MyPlayerOnCompletionListener()); //开始播放视频 vv.start();
class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener { @Override public void onCompletion(MediaPlayer mp) { Toast.makeText(MainActivity.this, "播放完成了", Toast.LENGTH_SHORT).show(); } }
为了防止用户可以快进,讲MediaController关闭