Skip to main content

Microsoft Silverlight

Unanswered Question Problem with looping soundsRSS Feed

(0)

abeaulieu
abeaulieu

Member

Member

660 points

112 Posts

Silverlight MVP

Problem with looping sounds

I would like to continuously loop a background sound.  I am using the following method, but there is a slight skip (no sound) between each loop of the sound....

In my xaml, I have:

           <MediaElement x:Name="soundX" Source="sounds/XXX.wma"></MediaElement>

In my code behind I have:

            soundX.MediaEnded += new EventHandler(soundX_MediaEnded);
            soundX.Play();

        void soundX_MediaEnded(object sender, EventArgs e)
        {
            soundX.Stop();
            soundX.Play();
        }

Is there another way to loop the sound without a skip?

 

Andy Beaulieu
www.andybeaulieu.com

If your question was answered, please mark the response as the answer.

Dave Relyea
Dave Relyea

Participant

Participant

1084 points

249 Posts

Microsoft

Re: Problem with looping sounds

That's the technique. One thing you can try is to to play the same sound twice, but start the second sound with an offset, e.g. if it is a 1s sound you are looping, start the same sound .5s later, also in a loop.

Also, some MP3s end with incomplete frames, so that may increase the silence between the repetitions.

GearWorld
GearWorld

Participant

Participant

840 points

1,101 Posts

Re: Problem with looping sounds

Cool a workaround.  But what is needed is a fix :)

 

Priyamjm
Priyamjm

Member

Member

234 points

32 Posts

Re: Problem with looping sounds

1        void soundX_MediaEnded(object sender, EventArgs e)
2        {
3            soundX.Stop();
4            soundX.Position = new TimeSpan(0);
5            soundX.Play();
6        }
7    
 

GearWorld
GearWorld

Participant

Participant

840 points

1,101 Posts

Re: Problem with looping sounds

The prolem is not the looping it's a glitch in reading the stream.  It looks like the first time a sound is played its nice and then the second time it looks like the sound plays half its content or sometimes if the sound is short enough it'll not play at all the second time.

 

bartczernicki
bartczer...

Contributor

Contributor

4078 points

723 Posts

Re: Problem with looping sounds

I saw people had good results using Encoder and using WMAs vs mp3s.

djprod
djprod

Member

Member

334 points

65 Posts

Re: Problem with looping sounds

see my reply to a similar question here:-

http://silverlight.net/forums/p/3599/141811.aspx#141811

Regars, Marc.

shamrat231
shamrat231

Contributor

Contributor

4649 points

591 Posts

Re: Problem with looping sounds

Here is a post by Jonathan about sound looping

Have a look

http://silverlight.net/forums/p/53437/138609.aspx

and if the post was helpful then please 'Mark as Answer' - many thanks

Sharker Khaleed Mahmud
Software Developer
(MCP,MCTS,MCPD[web])

This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.

Dhaka, Bangladesh
LinkedIn :: SL Profile :: Blog
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities