赞
踩
首先看一下效果
思路:就是算出当前要播放的clip 的长度 换算成时间,显示为这个音频的总时间 10:49
AudioSource.time 就是当前音频播放的时间 进行换算 就是为当前显示的播放时间 00:37
核心代码
- public AudioSource s2AudioManger;
- public AudioClip audio;
-
- private int clipHour;
- private int clipMinute;
- private int clipSecond;
-
- private int currentHour;
- private int currentMinute;
- private int currentSecond;
-
- private string audioTimeText;
-
-
- public void AudioLength ()
- {
- clipHour = (int)s2AudioManger.clip.length / 3600;
- clipMinute = (int)(s2AudioManger.clip.length - clipHour * 3600) / 60;
- clipSecond = (int)(s2AudioManger.clip.length - clipHour * 3600 - clipMinute * 60);
- Debug.Log ("clipHour" + clipHour);
- Debug.Log ("clipMinute" + clipMinute);
- Debug.Log ("clipSecond" + clipSecond);
- }
-
- public string ShowAudioTime ()
- {
- currentHour = (int)s2AudioManger.time / 3600;
- currentMinute = (int)(s2AudioManger.time - currentHour * 3600) / 60;
- currentSecond = (int)(s2AudioManger.time - currentHour * 3600 - currentMinute * 60);
- audioTimeText = string.Format ("{0:D2}:{1:D2}:{2:D2}/{3:D2}:{4:D2}:{5:D2}", currentHour, currentMinute, currentSecond, clipHour, clipMinute, clipSecond);
-
- return audioTimeText;
- }
- // 当前Slider 进度显示
- public float MusicSlider ()
- {
- return s2AudioManger.time / s2AudioManger.clip.length;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。