tags:

views:

223

answers:

1

Using XNA 4.0, I am currently playing songs from the user's PC/XBox360 using the following:

        Microsoft.Xna.Framework.Media.MediaPlayer.Play(Song song);

I see that MediaPlayer has a static Property PlayPosition that, as I've researched, used to be a get/set property, but it has been updated to get-only.

Are there any other methods/tricks I can use to explicitly set the playing position of a currently playing song?

+1  A: 

It looks liked they added a DynamicSoundEffectInstance class in XNA 4.0. One of the member functions is SubmitBuffer, which allows you to set the "Offset, in bytes, to the starting position of the data."

Please note that I haven't tried this out yet, and I couldn't tell you how to get your audio into a buffer of bytes (maybe you can read it from a XACT wavebank somehow?). It's also probably going to be a pain to do this because it doesn't look like you can remove the buffer if you decide to change position again. You would have to either let it play to the end or create a new class and submit a new buffer with a new offset. So you could keep your byte buffer in memory, and just pass it to new DynamicSoundEffectInstance classes with a new offset each time you wanted to change position.

Like I said, I haven't tried this out yet, and I'm just going by the documentation on MSDN. I searched around for a while, and Shawn Hargreaves said back in October '09 before XNA 4.0 came out that he doesn't think this can be done. Since the PlayPosition is still a get only property in XNA 4.0, I don't think you'll have any luck there, but the DynamicSoundEffectInstance is new and may give you what you need.

Venesectrix
"Shawn Hargreaves said back in October '09 before XNA 4.0 came out that he doesn't think this can be done."Looks like this is still the case, thanks for the heads up Venesectrix!
bufferz