Cómo: Repetir la reproducción de medios

Actualización: noviembre 2007

En este ejemplo se muestra cómo reproducir indefinidamente los elementos multimedia, es decir, establecerlos de modo que se reproduzcan en un bucle sin fin.

Ejemplo

En el ejemplo siguiente se utilizan MediaElement y MediaTimeline en Storyboard para reproducir un clip multimedia en un bucle sin fin.

<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://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>
<Page xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="https://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>

Para obtener el ejemplo completo, vea Ejemplo Media Gallery.

Vea también

Tareas

Ejemplo Media Gallery

Conceptos

Información general sobre características de gráficos, animación y multimedia en WPF

Referencia

MediaElement

MediaTimeline

Storyboard

Otros recursos

Temas "Cómo..." de audio y vídeo