Looping music with intro in XNA using SoundEffect
I have two sound files:
- Sound A is an 18 second intro designed to be played once
- Sound B is a 1 minute looping track
I'd like to play Sound A once, then once Sound A is done, immediately play Sound B and keep looping Sound B until I tell it to stop. This is supposed to be looping town music in an RPG.
I've tried doing this in code using just SoundEffect, but there's a tiny yet noticeable gap between the end of Sound A and the beginning of Sound B. Even if I put monitoring code watching Sound A's So开发者_Python百科undEffectInstance.State in the Update() function, I haven't been able to start Sound B exactly when Sound A finishes so that it's seamless.
I'd prefer to use SoundEffect because I can load WMA files rather than being stuck with WAVs in XACT.
A potentially second option. I'd imagine that the gap you're hearing is probably because the second sound needs to be either loaded into memory, or initialized, or the stream opened (not sure of the internal implementation). But if this is the case, I wonder if you could do something like this:
- Load the two sound effects (a and b)
- Begin playing sound effect A
- immediately begin playing sound effect B
- pause sound effect B after one frame
- when sound effect A finishes, restart sound effect A
My assumption is that since sound effect B is already initialized, it may start up quicker, thus lessening the perceived gap. Would love to hear if you get a chance to try this, and whether it worked :-)
Unfortunately, simplicity in the SoundEffect API is paid for by a reducing the flexibility. This type of audio programming is what XACT excels in ... if you require a complex composition then you probably want to investigate moving to XACT.
精彩评论