我是靠谱客的博主 强健饼干,这篇文章主要介绍Unity AVPro video 开始播放,播放完成事件监听,现在分享给大家,希望可以做个参考。

代码播放: 低版本的路径播放api 不是这个 

2.2.4 AVPro Video - Core Edition (核心版)

bool isOpening = mediaPlayer.OpenMedia(new MediaPath("VIdeos/PXPGameRule.mp4", MediaPathType.RelativeToStreamingAssetsFolder), autoPlay: true);

GetComponent<DisplayUGUI>().CurrentMediaPlayer = mediaPlayer;

功能:htc 手柄按下touchpad 或者 Grap 播放全景视频 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using RenderHeads.Media.AVProVideo; using System.Collections; using System.Collections.Generic; using UnityEngine; using Valve.VR; public class ViveControllerInput : MonoBehaviour { public MediaPlayer _mediaPlayer; public SteamVR_Action_Boolean m_TeleportAction; // 圆盘按下事件 public SteamVR_Action_Boolean m_GrapPinchAction; // Grap 按下事件 public SteamVR_Action_Single m_GrapPowerAction; // Grap 按下程度 public SteamVR_Action_Vector2 m_TeleportMoveAction; // 圆盘触摸事件 public SteamVR_Behaviour_Pose[] m_pose; // 获取手柄上的 SteamVR_Behaviour_Pose 组件 bool isPlaying = false; private void Start() { _mediaPlayer.Events.AddListener(OnMediaPlayerEvent); } void Update() { for (int i = 0; i < m_pose.Length; i++) { if (m_TeleportAction.GetStateDown(m_pose[i].inputSource)|| m_GrapPinchAction.GetStateDown(m_pose[i].inputSource)) { Debug.Log("任意一个手柄的Teleport圆盘按下 或者是 grap键 按下"); if (!isPlaying) { StartMovie("/AVProVideoSamples/SampleSphere.mp4"); Debug.Log("播放或者重新播放"); } } } Teleport 圆盘触摸坐标数据获取 //Vector2 TeleportPos = m_TeleportMoveAction.GetAxis(SteamVR_Input_Sources.Any); //Debug.Log("TeleportPos" + TeleportPos); //if (TeleportPos != Vector2.zero) //{ // // Debug.Log("TeleportPos" + TeleportPos); //} Grap 按下程度 //float m_GrapPower = m_GrapPowerAction.GetAxis(SteamVR_Input_Sources.Any); //Debug.Log(m_GrapPower); } public void OnMediaPlayerEvent(MediaPlayer mp,MediaPlayerEvent.EventType et,ErrorCode errorCode) { switch (et) { case MediaPlayerEvent.EventType.Started: print("startedEvent开始事件触发"); OnMediaPlayerStarted(mp); break; case MediaPlayerEvent.EventType.FinishedPlaying: print("finishedEvent结束事件触发"); OnMediaPlayerFinished(mp); break; } } void StartMovie(string mp4Str) { _mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, Application.streamingAssetsPath + mp4Str, true); _mediaPlayer.m_Loop = false; _mediaPlayer.Play(); } /// <summary> /// 开始事件触发 /// </summary> /// <param name="mp"></param> void OnMediaPlayerStarted(MediaPlayer mp) { print("开始事件触发的后续"); isPlaying = true; } /// <summary> /// 结束事件触发 /// </summary> /// <param name="mp"></param> void OnMediaPlayerFinished(MediaPlayer mp) { print("结束事件触发的后续"); isPlaying = false; } }

事件监听的方法转载自:

Unity视频插件AVPro Video的事件管理_thinkcg的博客-CSDN博客

最后

以上就是强健饼干最近收集整理的关于Unity AVPro video 开始播放,播放完成事件监听的全部内容,更多相关Unity内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(83)

评论列表共有 0 条评论

立即
投稿
返回
顶部