码迷,mamicode.com
首页 > 其他好文 > 详细

【框架】Vitamio多媒体播放器

时间:2016-05-05 12:49:15      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

 

<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; } }); } } }

 

【框架】Vitamio多媒体播放器

标签:

原文地址:http://www.cnblogs.com/anni-qianqian/p/5461241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!