您的位置:首页 > 移动开发 > Unity3D

使用AVPro Video插件完成切换多个视频播放功能

2017-05-02 13:59 886 查看

使用AVPro Video插件完成切换多个视频播放功能

功能:搭建好UI界面后,点击视频播放列表,跳转到相对应视频并且播放,点击播放的上一个或是下一个按钮,可以来回切换视频的播放

特点:使用了AVPro Video插件,在基于Demo文件夹下的Demo_VideoControls场景,修改了VCR脚本里的几个方法的逻辑

1.给每一个点击列表UI添加Button按钮,绑定脚本的Bofangliebiao方法,在获取VCR脚本时要去掉脚本自带的namespace RenderHeads.Media.AVProVideo.Demos保护类型,不然获取不到,点击列表播放视频时调用

public void Bofangliebiao()
{
var sender = EventSystem.current.currentSelectedGameObject;

switch (sender.name)
{
case "冲裁间隙对冲压质量的影响":
tiaozhan(0);
break;
case "凸凹模刃口尺寸计算":
tiaozhan(1);
break;
case "冲裁力与模具设计":
tiaozhan(2);
break;
case "相对弯曲半径":
tiaozhan(3);
break;
case "弯曲成形回弹":
tiaozhan(4);
break;
case "拉伸系数的影响":
tiaozhan(5);
break;
case "压边力的影响":
tiaozhan(6);
break;
default:
break;

}
}
public void tiaozhan(int aa)
{
VCR._VideoIndex = aa;
GameObject.Find("VCR").GetComponent<VCR>().OnOpenVideoFile();
GameObject.Find("VCR").GetComponent<VCR>().OnPlayButton();

}


2.导入AVPro Video插件后,在VCR脚本的视频播放数组上添加要播放的多个视频;



并且改变VCR脚本自定义的 string[] _videoFiles数组的值;



3.在上一个button按钮上绑定VCR.OnLastVideoFile方法,

在下一个button按钮上绑定VCR.OnNextVideoFile方法,执行代码



代码如下:

public static int _VideoIndex = 0;

3.         public void OnOpenVideoFile()
4.         {
5.             _mediaPlayer.m_VideoPath = string.Empty;
6.             _mediaPlayer.m_VideoPath = _videoFiles[_VideoIndex];
7.             _VideoIndex = (_VideoIndex) % (_videoFiles.Length);
8.             if (string.IsNullOrEmpty(_mediaPlayer.m_VideoPath))
9.             {
10.                 _mediaPlayer.CloseVideo();
11.
12.                 _VideoIndex = 0;
13.             }
14.             else
15.             {
16.                 _mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, _mediaPlayer.m_VideoPath, _AutoStartToggle.isOn);
17.
18.                 OnPlayButton();
19.
20.                 //              SetButtonEnabled( "PlayButton", !_mediaPlayer.m_AutoStart );
21.                 //              SetButtonEnabled( "PauseButton", _mediaPlayer.m_AutoStart );
22.             }
23.         }
24.
25.         //切换到下一个视频
26.         public void OnNextVideoFile()
27.         {
28.             if (_VideoIndex < _videoFiles.Length&&_VideoIndex>=0)
29.             {
30.                 _VideoIndex = (_
4000
VideoIndex + 1) % (_videoFiles.Length);
31.                 _mediaPlayer.m_VideoPath = string.Empty;
32.                 _mediaPlayer.m_VideoPath = _videoFiles[_VideoIndex];
33.                 if (string.IsNullOrEmpty(_mediaPlayer.m_VideoPath))
34.                 {
35.                     _mediaPlayer.CloseVideo();
36.
37.                     _VideoIndex = 0;
38.                 }
39.                 else
40.                 {
41.                     _mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, _mediaPlayer.m_VideoPath, _AutoStartToggle.isOn);
42.
43.                     OnPlayButton();
44.
45.                     //              SetButtonEnabled( "PlayButton", !_mediaPlayer.m_AutoStart );
46.                     //              SetButtonEnabled( "PauseButton", _mediaPlayer.m_AutoStart );
47.                 }
48.             }
49.             else return;
50.
51.         }
52.         //切换到上一个视频
53.         public void OnLastVideoFile()
54.         {
55.             if (_VideoIndex > 0)
56.             {
57.                 _VideoIndex = (_VideoIndex - 1) % (_videoFiles.Length);
58.                 _mediaPlayer.m_VideoPath = string.Empty;
59.                 _mediaPlayer.m_VideoPath = _videoFiles[_VideoIndex];
60.                 if (string.IsNullOrEmpty(_mediaPlayer.m_VideoPath))
61.                 {
62.                     _mediaPlayer.CloseVideo();
63.                     // _VideoIndex = 0;
64.                 }
65.                 else
66.                 {
67.                     _mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, _mediaPlayer.m_VideoPath, _AutoStartToggle.isOn);
68.                     OnPlayButton();
69.                 }
70.
71.             }
72.             else return;
73.
74.         }


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