您的位置:首页 > 其它

手机影音4--视频播放器的基本功能(1)

2016-11-13 18:13 218 查看
1 <LinearLayout
2     android:id="@+id/ll_bottom"
3     android:layout_width="match_parent"
4     android:layout_height="wrap_content"
5     android:layout_alignParentBottom="true"
6     android:orientation="vertical">
7
8     <LinearLayout
9         android:layout_width="match_parent"
10         android:layout_height="wrap_content"
11         android:background="@drawable/bg_player_bottom_seekbar"
12         android:gravity="center_vertical"
13         android:orientation="horizontal">
14
15         <TextView
16             android:id="@+id/tv_current_time"
17             android:layout_width="wrap_content"
18             android:layout_height="wrap_content"
19             android:layout_marginLeft="8dp"
20             android:text="0:00"
21             android:textColor="#ffffff" />
22
23         <SeekBar
24             android:id="@+id/seekbar_video"
25             android:layout_width="match_parent"
26             android:layout_height="wrap_content"
27             android:layout_marginLeft="8dp"
28             android:layout_marginRight="8dp"
29             android:layout_weight="1"
30             android:maxHeight="6dp"
31             android:minHeight="6dp"
32             android:progressDrawable="@drawable/progress_horizontal"
33             android:thumb="@drawable/progress_thumb" />
34
35         <TextView
36             android:id="@+id/tv_duration"
37             android:layout_width="wrap_content"
38             android:layout_height="wrap_content"
39             android:layout_marginRight="8dp"
40             android:text="20:00"
41             android:textColor="#ffffff" />
42
43     </LinearLayout>
44
45
46     <LinearLayout
47         android:layout_width="match_parent"
48         android:layout_height="wrap_content"
49         android:background="@drawable/bg_player_bottom_control"
50         android:gravity="center_vertical"
51         android:orientation="horizontal">
52
53         <Button
54             android:id="@+id/btn_exit"
55             android:layout_width="wrap_content"
56             android:layout_height="wrap_content"
57             android:layout_weight="1"
58             android:background="@drawable/btn_exit_selector" />
59
60         <Button
61             android:id="@+id/btn_video_pre"
62             android:layout_width="wrap_content"
63             android:layout_height="wrap_content"
64             android:layout_weight="1"
65             android:background="@drawable/btn_video_pre_selector" />
66
67         <Button
68             android:id="@+id/btn_video_start_pause"
69             android:layout_width="wrap_content"
70             android:layout_height="wrap_content"
71             android:layout_weight="1"
72             android:background="@drawable/btn_video_pause_selector" />
73
74         <Button
75             android:id="@+id/btn_video_next"
76             android:layout_width="wrap_content"
77             android:layout_height="wrap_content"
78             android:layout_weight="1"
79             android:background="@drawable/btn_video_next_selector" />
80
81         <Button
82             android:id="@+id/btn_video_siwch_screen"
83             android:layout_width="wrap_content"
84             android:layout_height="wrap_content"
85             android:layout_weight="1"
86             android:background="@drawable/btn_video_siwch_screen_full_selector" />
87     </LinearLayout>
88
89 </LinearLayout>


View Code

4.视频seekBar进度更新

1.视频的总时长和SeekBar的setMaxt(总时长); 注意:准备好了的回调后

2.实例化Handler,每秒得到当前视频播放进度,SeekBar.setProgress(当前进度);

int duration = videoview.getDuration();
//把毫秒转换成 12:22.40
tv_duration.setText(utils.stringForTime(duration));

//设置视频的总长度为video_seekBar的多少等分
video_seekBar.setMax(duration);

//发消息开始更新
handler.sendEmptyMessage(PROGRESS);


5.实现视频的拖动

video_seekBar.setOnSeekBarChangeListener(newOnSeekBarChangeListener() {

//手指停止滑动的时候回调
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}

//手指刚开始滑动的时候回调
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

//手指滑动状态发送变化的时候回调
@Override
public void onProgressChanged(SeekBar seekBar, int progress,booleanfromUser) {
if(fromUser){
//          seekBar.setProgress(progress);
videoview.seekTo(progress);
}
}

});


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: