keijiro/MidiAnimationTrack

Midi Offset at first play.

papitosan opened this issue · 4 comments

I noticed that on the first play in Unity editor the midi is offset with audio track by 3/4 seconds (midi is ahead).
If I stop and play it again, everything is OK.

Sometimes Build is offsync as well.

I don't think it comes from Unity timeline since only the midi file is ahead.

Do you what could be the problem?

Best regards.

Is this issue reproducible with the sample project (the project in this repository)?

It doesn't reproduce on my side with the sample project.

Seems it can't be reproduced with the sample project.
I contacted someone from Unity about that. I keep you in touch.
Regards

Could you provide a minimal project that can reproduce the issue?

It seems that the issue was related to unity.
I Turned off play on awake on the playable director, and start playing the timeline from Start method instead that gives the scene time to load or initialize before the timeline starts playing.
Now everything is in sync.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;

public class TimelinePlay : MonoBehaviour
{
private PlayableDirector director;
public GameObject controlPanel;

private void Start()
{
    StartTimeline();
}
private void Awake()
{
    director = GetComponent<PlayableDirector>();
    director.played += Director_Played;
    director.stopped += Director_Stopped;
}

private void Director_Stopped(PlayableDirector obj)
{
    controlPanel.SetActive(true);
}

private void Director_Played(PlayableDirector obj)
{
    controlPanel.SetActive(false);
}

public void StartTimeline()
{
    director.Play();
}

}

Thanks keijiro san