1.使用AVPro Video插件,进行制作
2.效果演示
文章来源:https://www.toymoban.com/news/detail-772335.html
3.代码文章来源地址https://www.toymoban.com/news/detail-772335.html
void Start()
{
MediaPlayerone.m_VideoPath = Application.streamingAssetsPath + "/字言奇说.mp4";
MediaPlayerone.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, MediaPlayerone.m_VideoPath, true);
}
// Update is called once per frame
void Update()
{
//视频当前时长
one.text = convertime(GetCurrenAllTime());
//视频总时长
two.text = convertime(GetMovieAllTime());
if(time)
{
Sliderone.value = MediaPlayerone.Control.GetCurrentTimeMs();
}
}
public MediaPlayer MediaPlayerone;
public Text one;
public Text two;
public Slider Sliderone;
public Slider audioSliderone;
public float num;
//public ServerControllerSample sample;
public Dropdown Dropdownone;
//视频显示 总时间
public float GetMovieAllTime()
{
//毫秒 获取视频总时间
Sliderone.maxValue = MediaPlayerone.Info.GetDurationMs();
return MediaPlayerone.Info.GetDurationMs();
}
//视频 当前时间
public float GetCurrenAllTime()
{
//毫秒 获取视频当前播放时间
//Sliderone.value = MediaPlayerone.Control.GetCurrentTimeMs();
return MediaPlayerone.Control.GetCurrentTimeMs();
}
public string convertime(float time)
{
int scecond = (int)(time / 1000f);
int min = scecond / 60;
scecond = scecond % 60;
//三目运算符
return scecond < 10 ? "0" + min + ":" + "0" + scecond : "0" + min + ":" + scecond;
}
//开始拖拽 视频停止播放
public void stop()
{
time = false;
MediaPlayerone.Pause();
}
public bool time=true;
//结束拖拽 视频播放 跳转到规定位置
public void pause()
{
time = true;
MediaPlayerone.Play();
num = Sliderone.value;
MediaPlayerone.Control.Seek(num);
}
//倍速
public void dropdown()
{
if (Dropdownone.value == 0)
{
MediaPlayerone.Control.SetPlaybackRate(0.5f);
}
if (Dropdownone.value == 1)
{
MediaPlayerone.Control.SetPlaybackRate(1f);
}
if (Dropdownone.value == 2)
{
MediaPlayerone.Control.SetPlaybackRate(1.5f);
}
}
//视频快进或后退的时间
public float m_backSeconds;
//视频快进
public void kuaijin()
{
float currentime = MediaPlayerone.Control.GetCurrentTimeMs();
currentime = (currentime + m_backSeconds * 1000) >= 0 ? currentime + m_backSeconds * 1000 : currentime;
print("时间:"+currentime);
MediaPlayerone.Control.Seek(currentime);
}
//视频后退
public void tui()
{
float currentime = MediaPlayerone.Control.GetCurrentTimeMs();
currentime = (currentime - m_backSeconds * 1000) >= 0 ? currentime -m_backSeconds * 1000 : currentime;
MediaPlayerone.Control.Seek(currentime);
}
//音量控制
public void control()
{
float a = audioSliderone.value;
MediaPlayerone.Control.SetVolume(a);
}
到了这里,关于Unity学习记录4——视频进度条制作,视频倍速、快进及后退的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!