Reputation: 667
Im using a plugin from the unity asset store and trying to get video playing with sound - currently its not. Here is the script that plays the video --
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();
}
}
}
I tried adding the audio stuff following
http://justcode.me/unity2d/how-to-play-videos-on-unity-using-new-videoplayer/
but no luck. Audio still wouldn't play.
Upvotes: 0
Views: 868
Reputation: 1
In case you are using the Unity Video Player:
Upvotes: 0