Example #1
0
        // Called every frame that the timeline is evaluated. This is called prior to
        // PrepareFrame on any of its input playables.
        public override void PrepareFrame(Playable playable, FrameData info)
        {
            // Searches for clips that are in the 'preload' area and prepares them for playback
            var timelineTime = playable.GetGraph().GetRootPlayable(0).GetTime();

            for (int i = 0; i < playable.GetInputCount(); i++)
            {
                if (playable.GetInput(i).GetPlayableType() != typeof(VideoPlayableBehaviour))
                {
                    continue;
                }

                if (playable.GetInputWeight(i) <= 0.0f)
                {
                    ScriptPlayable <VideoPlayableBehaviour> scriptPlayable = (ScriptPlayable <VideoPlayableBehaviour>)playable.GetInput(i);
                    VideoPlayableBehaviour videoPlayableBehaviour          = scriptPlayable.GetBehaviour();
                    double preloadTime = Math.Max(0.0, videoPlayableBehaviour.preloadTime);
                    double clipStart   = videoPlayableBehaviour.startTime;

                    if (timelineTime > clipStart - preloadTime && timelineTime <= clipStart)
                    {
                        videoPlayableBehaviour.PrepareVideo();
                    }
                }
            }
        }
Example #2
0
        // Creates the playable that represents the instance that plays this clip.
        // Here a hidden VideoPlayer is being created for the PlayableBehaviour to use
        // to control playback. The PlayableBehaviour is responsible for deleting the player.
        public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
        {
            Camera camera = targetCamera.Resolve(graph.GetResolver());

            if (camera == null)
            {
                camera = Camera.main;
            }

            // If we are unable to create a player, return a playable with no behaviour attached.
            VideoPlayer player = CreateVideoPlayer(camera, audioSource.Resolve(graph.GetResolver()));

            if (player == null)
            {
                return(Playable.Create(graph));
            }

            ScriptPlayable <VideoPlayableBehaviour> playable =
                ScriptPlayable <VideoPlayableBehaviour> .Create(graph);

            VideoPlayableBehaviour playableBehaviour = playable.GetBehaviour();

            playableBehaviour.videoPlayer = player;
            playableBehaviour.preloadTime = preloadTime;
            playableBehaviour.clipInTime  = clipInTime;
            playableBehaviour.startTime   = startTime;

            return(playable);
        }