HOW TO:重複播放媒體How to: Repeat Media Playback

此範例顯示如何無限期地撥放,亦即,將媒體設定為不斷地重播。This example shows how to playback media indefinitely, that is, to set media so that it plays in an infinite loop.

範例Example

下列範例會使用MediaElementMediaTimelineStoryboard播放媒體短片,無限迴圈。The following example uses MediaElement and MediaTimeline in a Storyboard to play a media clip in an infinite loop.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <StackPanel>

    <!-- The MediaElement control plays the sound. -->
    <MediaElement Name="myMediaElement" >
      <MediaElement.Triggers>
        <EventTrigger RoutedEvent="MediaElement.Loaded">
          <EventTrigger.Actions>
            <BeginStoryboard>
              <Storyboard>

                <!-- The MediaTimeline has a RepeatBehavior="Forever" which makes the media play
                     over and over indefinitely.-->
                <MediaTimeline Source="media\tada.wav" Storyboard.TargetName="myMediaElement"  
                 RepeatBehavior="Forever" />

              </Storyboard>
            </BeginStoryboard>
          </EventTrigger.Actions>
        </EventTrigger>
      </MediaElement.Triggers>
    </MediaElement>

  </StackPanel>
</Page>

另請參閱See also