AVProVideo视频进度条

1,新建slider并添加事件

 1  public MediaPlayer _mediaPlayer;
 2     public Slider _videoSeekSlider;
 3     public Text time;
 4     float _setVideoSeekSliderValue;
 5     private bool _wasPlayingOnScrub;
 6 
 7     void Update()
 8     {
 9 
10         int _all = (int)float.Parse((_mediaPlayer.m_Info.GetDurationMs() * 0.001f).ToString("F1"));
11         TimeSpan allTime = new TimeSpan(0, 0, _all);
12 
13         int _current = (int)float.Parse((_mediaPlayer.m_Control.GetCurrentTimeMs() * 0.001f).ToString("F1"));
14         TimeSpan currentTime = new TimeSpan(0, 0, _current);
15 
16         time.text = currentTime.Hours + ":" + currentTime.Minutes + ":" + currentTime.Seconds + "/" + allTime.Hours + ":" + allTime.Minutes + ":" + allTime.Seconds;
17         if (_mediaPlayer && _mediaPlayer.Info != null && _mediaPlayer.Info.GetDurationMs() > 0f)
18         {
19             float time = _mediaPlayer.Control.GetCurrentTimeMs();
20             float d = time / _mediaPlayer.Info.GetDurationMs();
21             _setVideoSeekSliderValue = d;
22             _videoSeekSlider.value = d;
23         }
24     }
25 
26     public void OnVideoSeekSlider()
27     {
28         if (_mediaPlayer && _videoSeekSlider && _videoSeekSlider.value != _setVideoSeekSliderValue)
29         {
30             _mediaPlayer.Control.Seek(_videoSeekSlider.value * _mediaPlayer.Info.GetDurationMs());
31         }
32     }
33 
34 
35     public void OnVideoSliderBegin()
36     {
37         if (_mediaPlayer)
38         {
39             _wasPlayingOnScrub = _mediaPlayer.Control.IsPlaying();
40             if (_wasPlayingOnScrub)
41             {
42                 _mediaPlayer.Control.Pause();
43               
44             }
45             OnVideoSeekSlider();
46         }
47     }
48 
49     public void OnVideoSliderEnd()
50     {
51         if (_mediaPlayer && _wasPlayingOnScrub)
52         {
53             _mediaPlayer.Control.Play();
54             _wasPlayingOnScrub = false;
55 
56         }
57     }

 

AVProVideo视频进度条_第1张图片

 

转载于:https://www.cnblogs.com/y1016/p/9674492.html

你可能感兴趣的:(AVProVideo视频进度条)