Question

I want to have a video repeating forever until in my viewmodel I change the video source. But i'am not able to achive this 2 behaviors togheter. I'm using this axml:

<MediaElement Name="myMediaElement" Margin="10" LoadedBehavior="Play">
<MediaElement.Triggers>
    <EventTrigger RoutedEvent="MediaElement.Loaded">
        <EventTrigger.Actions>
            <BeginStoryboard>
                <Storyboard>
                    <MediaTimeline Source="{Binding FaseTest.VideoUri}"
                    Storyboard.TargetName="myMediaElement" RepeatBehavior="Forever" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger.Actions>
    </EventTrigger>
</MediaElement.Triggers>

If i dont' use Trigger changing video works but i dont't have the repeating behavior. If i use Trigger repeating behavior work but changing video not.

Was it helpful?

Solution

I resolved using a an eventhandler for the mediaelement and removing the eventtriggers and mediatimeline:

<MediaElement Name="myMediaElement" Margin="10" Source="{Binding FaseTest.VideoUri}" 
 LoadedBehavior="Play" UnloadedBehavior="Manual" MediaEnded="MediaEnded" >

and

private void MediaEnded( object sender, RoutedEventArgs e )
    {
        myMediaElement.Position = TimeSpan.Zero;
        myMediaElement.Play();
    }

I know that this is a little bit dirty... but i'am unable to find another working solution without using backcoding.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top