Making project with SteamVR and unity 5.6.0f3. making a simple switching video mechanism and everytime the videoclip switches within the videoplayer and it plays the new clip. it causes a CPU usage spike which shows that the problem is with VideoPlayer.set_clip()
and my steamVR switches from the application to the compositor screen for a split second.
My settings for the videoplayer is
I have also tried stopping the clip before switching and playing again.
This is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
[RequireComponent(typeof(AudioSource))]
public class PlayVideo : MonoBehaviour
{
public VideoClip clip;
private SerialUISummoner canvas;
VideoPlayer video;
int vsyncprevious;
private bool playing = false;
// Use this for initialization
void Start()
{
video = GetComponent<VideoPlayer>();
video.clip = clip;
video.SetTargetAudioSource(0, GetComponent<AudioSource>());
canvas = Object.FindObjectOfType<SerialUISummoner>();
}
// Update is called once per frame
void Update()
{
if (canvas != null)
{
if (canvas.Showing && !playing)
{
playing = true;
print("START");
PlayVid();
}
if (!canvas.Showing && playing)
{
playing = false;
StopVid();
}
}
}
public void PlayVid()
{
video.Play();
}
public void StopVid()
{
video.Stop();
}
public void Change()
{
if (video != null)
{
playing = false;
video.clip = clip;
playing = true;
PlayVid();
}
}
}