Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Sound thats loops RSS

9 replies

Last post Jan 07, 2009 11:37 AM by vyfster

(0)
  • vyfster

    vyfster

    Member

    1 Points

    14 Posts

    Sound thats loops

    Nov 27, 2008 12:54 PM | LINK

    Hi,

    I would like a mp3 to play when the page loads and then to continue looping. I am not quite sure how to go about doing this, does anyone have an ideas for me or an URL that I can check it out at?

    Thanks

  • preishuber

    preishuber

    Contributor

    3572 Points

    658 Posts

    Re: Sound thats loops

    Nov 27, 2008 01:04 PM | LINK

    as i remember there is a media ended event

    there you can repostion to start and call play()

    -Hannes

    http://www.ppedv.de
  • vyfster

    vyfster

    Member

    1 Points

    14 Posts

    Re: Sound thats loops

    Nov 27, 2008 01:45 PM | LINK

    Hi Hannes,

    Thanks for your reply to this post. Maybe I jumped the gun slightly, I have not got the sound working yet. Looping it would be the next step in the process. I have added the media element to my canvas, then in the C# file I have tried to reference it in the same way that I would a storyboard but it does not work. Is this the correct way or should I be trying this another way?

    void Page_Loaded(object sender, RoutedEventArgs e)

    {

    track_mp3.Play();

    }

    Thanks

  • shamrat231

    shamrat231

    Star

    10748 Points

    1283 Posts

    Re: Sound thats loops

    Nov 27, 2008 03:35 PM | LINK

    Here you go.

     <MediaElement x:Name="media" Source="xbox.wmv"
        Width="300" Height="300" />

    By default, the media that is defined by the Source property plays immediately after the MediaElement object has loaded. To suppress the media from starting automatically, set the AutoPlay property to false or in your case set it to true.

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

    Sharker Khaleed Mahmud (MCPD)
    Software Developer

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

  • Jonathan Shen – MSFT

    Jonathan She...

    All-Star

    50156 Points

    4951 Posts

    Microsoft

    Re: Sound thats loops

    Dec 03, 2008 08:49 AM | LINK

    Hi Vyfster,

    To make the video display automatically, we need to set its AutoPlay to "Ture".  

    To make it loop, we need to replay the video on MediaEnded event.  For example,

     <MediaElement x:Name="media" Source="midnight.wmv"  Width="300" Height="300" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" AutoPlay="True" MediaEnded="PlayMedia"/>

            private void PlayMedia(object sender, RoutedEventArgs e)
            {
                media.Stop();
                media.Play();
            }

    Best regards,

    Jonathan

     

    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
  • GearWorld

    GearWorld

    Participant

    1788 Points

    2080 Posts

    Re: Sound thats loops

    Dec 10, 2008 11:06 AM | LINK

    Any release date for a silverlight patch to correct the short sound problem by the way ?

     

  • vyfster

    vyfster

    Member

    1 Points

    14 Posts

    Re: Sound thats loops

    Jan 06, 2009 12:33 PM | LINK

    Hi Jonathan,

     I went to sleep on this post and have only picked it upi gain now. I have managed to get the media element playing, it was a little tricky at first but I understand how it is done now. It is added from the asset library and then dragged and dropped onto the stage. I was looking for an actual media element. The second part of your post has me confused though. Where is it added into the code behind file? I keep on getting build error's so I must be adding it incorrectly.

    /* where in the code behind file does this code get added? */  

    private void PlayMedia(object sender, RoutedEventArgs e)
            {
                media.Stop();
                media.Play();
            }

     

    Thanks for your input so far.

  • fullsailrick

    fullsailrick

    Contributor

    3699 Points

    829 Posts

    Re: Re: Sound thats loops

    Jan 06, 2009 08:45 PM | LINK

    Hook a "Completed" handle to your media element with

    this.BikiniGirls.MediaEnded += new RoutedEventHandler(BikiniGirls_MediaEnded);

    ^ do that somewhere in initialization-- and when the girls stop dancing on the trampoline it will automagically call this function

    private void BikiniGirls_MediaEnded(object sender, RoutedEventArgs e)
    {
    Bikinigirls.stop();
    BikiniGirls.Position = TimeSpan.FromSeconds(0);
    Bikinigirls.Play();
    }

    note: this only will work for dancing bikini girls, i've never tested it with music.
  • fullsailrick

    fullsailrick

    Contributor

    3699 Points

    829 Posts

    Re: Re: Re: Sound thats loops

    Jan 06, 2009 08:49 PM | LINK

    LOL I just noticed that Jonathan did the same thing. But he left out the Position which I've always had to set when looking at bikinigirls. So I'm more specialer. I love you Jonathan.

    Seriously though, set the Position to 0 and then play it and it will work.
  • vyfster

    vyfster

    Member

    1 Points

    14 Posts

    Re: Sound thats loops

    Jan 07, 2009 11:37 AM | LINK

    Thanks for all the help guys.

    This is what finally worked. I just left off the  track_mp3.Stop(); and it now loops. Previously it played once and then stopped.

     

    void
    track_mp3_MediaEnded(object sender, RoutedEventArgs e)

    {

    track_mp3.Play();

    track_mp3.Position = TimeSpan.FromSeconds(0);

    }