标签:
<io.vov.vitamio.widget.VideoView android:id="@+id/video_view" android:layout_width="match_parent" android:layout_height="200dp" android:layout_centerInParent="true"/> <TextView android:id="@+id/current_percent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/video_view" android:padding="12dp" android:text="百分比" android:textColor="#ffffff" android:visibility="gone"/> <TextView android:id="@+id/net_speed" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/video_view" android:layout_toRightOf="@id/current_percent" android:padding="12dp" android:text="网速" android:textColor="#ffffff" android:visibility="gone"/>
public class MainActivity extends AppCompatActivity { private TextView percentTv; private TextView netSpeedTv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Vitamio.initialize(this)返回值表示是否初始化成功 if (Vitamio.initialize(this)) { VideoView videoView = (VideoView) findViewById(R.id.video_view); percentTv = (TextView) findViewById(R.id.current_percent); netSpeedTv = (TextView) findViewById(R.id.net_speed); videoView.setVideoURI(Uri.parse("http://112.253.22.157/17/z/z/y/u/zzyuasjwufnqerzvyxgkuigrkcatxr/hc.yinyuetai.com
/D046015255134077DDB3ACA0D7E68D45.flv")); MediaController controller = new MediaController(this); videoView.setMediaController(controller); videoView.start(); //设置Vitamio的缓冲监听 videoView.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() { @Override public void onBufferingUpdate(MediaPlayer mp, int percent) { percentTv.setText("已缓冲:" + percent + "%"); } }); //设置监听VideoView的缓冲监听 videoView.setOnInfoListener(new MediaPlayer.OnInfoListener() { //what表示当前是刚开始缓冲还是缓冲结束还是正在缓冲 //extra表示缓冲的网速 @Override public boolean onInfo(MediaPlayer mp, int what, int extra) { switch (what) { //表示开始缓冲 case MediaPlayer.MEDIA_INFO_BUFFERING_START: percentTv.setVisibility(TextView.VISIBLE); netSpeedTv.setVisibility(View.VISIBLE); //暂停播放 mp.pause(); break; //表示缓冲结束 case MediaPlayer.MEDIA_INFO_BUFFERING_END: percentTv.setVisibility(View.GONE); netSpeedTv.setVisibility(View.GONE); //缓冲结束后接着播放 mp.start(); break; //正在缓冲 case MediaPlayer.MEDIA_INFO_DOWNLOAD_RATE_CHANGED: netSpeedTv.setText("当前下载速率:" + extra + "kb/s"); break; } return true; } }); } } }
标签:
原文地址:http://www.cnblogs.com/anni-qianqian/p/5461241.html