我在XNA創造一個遊戲,將有很多音樂的工作遍歷對方,但我似乎不能夠同步這些聲音。C#音樂/聲音同步
我總是想念幾毫秒你能幫我嗎?
這是我第一次嘗試同步聲音。要知道我需要幾十聲音的工作...
也許這個問題的同步與緩存的聲音有關係嗎?
有沒有一個外部庫使它更容易?
public SoundEffectInstance loop1, loop2;
public int auxControl = 0;
public bool auxB = false, auxA = false;
public void LoadContent()
{
SoundEffect temp1 = Game.Content.Load<SoundEffect>("sounds/Synctest_1");
loop1 = temp1.CreateInstance();
loop1.IsLooped = true;
loop2 = temp1.CreateInstance();
loop2.IsLooped = true;
}
public override void Update(GameTime gameTime)
{
// start first sound
if (auxA == false)
loop1.Play(); auxA = true;
// start counting until 2 seconds
if (auxA)
auxControl += gameTime.ElapsedGameTime.Milliseconds;
// if 2 seconds have passed after first sound start second sound
if (auxControl >= 2000 && auxB == false)
{
loop2.Play();
auxB = true;
}
base.Update(gameTime);
}
謝謝
如果所有的循環是相同的長度(或其倍數),你可以使用一個DispatcherTimer優先級高玩上設定的時間間隔每個新以獲得更高精度和更乾淨的代碼在YMMV之前從未嘗試過。 –