我正在使用统一资产商店的插件并尝试播放带有声音的视频 - 目前不是。以下是播放视频的脚本 -
using UnityEngine;
using UnityEngine.Video;
namespace Complete360Tour {
[AddComponentMenu("Complete360Tour/Media/VideoMediaReactor")] public class VideoMediaReactor : MonoBehaviour, IMediaSwitchReactor<VideoMediaNodeData> {
//-----------------------------------------------------------------------------------------
// Inspector Variables:
//-----------------------------------------------------------------------------------------
[Header("Assignment")] [SerializeField] protected MediaView mediaView;
[SerializeField] protected VideoPlayer videoPlayer;
//-----------------------------------------------------------------------------------------
// Private Fields:
//-----------------------------------------------------------------------------------------
private RenderTexture renderTexture;
//-----------------------------------------------------------------------------------------
// Unity Lifecycle:
//-----------------------------------------------------------------------------------------
protected void Awake() {
if (mediaView == null) Debug.LogWarning("No MediaView assigned. Please assign a MediaView.");
}
//-----------------------------------------------------------------------------------------
// Public Methods:
//-----------------------------------------------------------------------------------------
public void SwitchMedia(VideoMediaNodeData data, MediaSwitchStates state) {
if (data == null) {
InvalidSwitchData();
return;
}
switch (state) {
case MediaSwitchStates.BeforeSwitch: break;
case MediaSwitchStates.Switch:
BeginVideo(data.VideoClip);
mediaView.SetStereoscopic(data.IsStereo);
break;
case MediaSwitchStates.AfterSwitch: break;
}
}
public void ExitMedia() { InvalidSwitchData(); }
//-----------------------------------------------------------------------------------------
// Private Methods:
//-----------------------------------------------------------------------------------------
private void InvalidSwitchData() {
videoPlayer.Stop();
videoPlayer.targetTexture = null;
mediaView.SetMedia(null);
mediaView.SetStereoscopic(false);
}
private void BeginVideo(VideoClip videoClip) {
renderTexture = new RenderTexture((int) videoClip.width, (int) videoClip.height, 0);
videoPlayer.clip = videoClip;
videoPlayer.targetTexture = renderTexture;
mediaView.SetMedia(renderTexture);
videoPlayer.Play();
}
}
}
我尝试添加
之后的音频内容http://justcode.me/unity2d/how-to-play-videos-on-unity-using-new-videoplayer/
但没有运气。音频仍然无法播放。
答案 0 :(得分:0)
如果您使用的是Unity Video Player: