我在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之前从未尝试过。 –