tags:

views:

1009

answers:

2

Hi, this is driving me pretty crazy. I'm trying to get a WMV file to autoreverse after it's done playing, but it doesn't work. I've tried setting Storyboard autoreverse to true, but this throws an error saying that

"Clocks with CanSlip cannot have parents or ancestors with AutoReverse, AccelerationRatio, or DecelerationRatio."

Is this because I'm not using animation but a video? How can I achieve the same thing? The video I've got is working, both play and pause and resume. But after it's finished it just stops.

I've got three storyboards all together, one which is the video itself. And two where there's an animation which fades out a white rectangle just as the video plays and pauses.

The code looks like this:

public partial class Window1
{

    public Storyboard RectangleFadeA;
    public Storyboard RectangleFadeBackA;
    public Storyboard VideoA;

    bool isPlaying;
    bool isPaused;

    public Window1()
    {
        this.InitializeComponent();

        // Insert code required on object creation below this point.
        RectangleFadeA = (Storyboard)TryFindResource("RectangleFadeA");
        RectangleFadeBackA = (Storyboard)TryFindResource("RectangleFadeBackA");
        VideoA = (Storyboard)TryFindResource("GTTV_promo_wmv");          

        isPlaying = false;
        isPaused = false;
    }


    private void rectangle_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        if (!isPlaying)
        {
            if (!isPaused)
            {

                if (RectangleFadeA != null)
                    RectangleFadeA.Begin(this, true);

                if (VideoA != null)
                    VideoA.Begin(this, true);

                isPlaying = true;
                return;

            }
            if (isPaused)
            {
                if (RectangleFadeA != null)
                    RectangleFadeA.Begin(this, true);
                if (VideoA != null)
                    VideoA.Resume(this);
                isPaused = false;
                isPlaying = true;
                return;
            }
        }

        if (isPlaying)
        {
            if (RectangleFadeBackA != null)
                RectangleFadeBackA.Begin(this, true);
            VideoA.Pause(this);
            isPlaying = false;
            isPaused = true;
            return;

        }



    }

}
A: 

I know there's something called Storyboard.Completed, but I can't get it to trigger. Does anyone have any idea?

Kenny Bones
+1  A: 

Just found the solution without much code. First of all, I set the video (MediaTimeLine) to repeatbehaviour=forever. Then I add an Event Handler to the MediaElement at "MediaEnded"

And the C# code looks like this:

private void GTTV_promo_wmv_MediaEnded(object sender, RoutedEventArgs e)
    {
        RectangleFadeBackA.Begin(this, true);
        VideoA.Pause(this);
        isPaused = true;
        isPlaying = false;
        return;

    }

So, the complete C# code so far looks like this:

public partial class Window1
{
    public Storyboard RectangleFadeA;
    public Storyboard RectangleFadeBackA;

    public Storyboard VideoA;

    bool isPlaying;
    bool isPaused;


    public Window1()
    {
        this.InitializeComponent();

        // Insert code required on object creation below this point.
        RectangleFadeA = (Storyboard)TryFindResource("RectangleFadeA");
        RectangleFadeBackA = (Storyboard)TryFindResource("RectangleFadeBackA");
        VideoA = (Storyboard)TryFindResource("GTTV_promo_wmv");
        isPlaying = false;
        isPaused = false;

    }

    private void rectangle_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        if (!isPlaying)
        {
            if (!isPaused)
            {

                if (RectangleFadeA != null)
                    RectangleFadeA.Begin(this, true);

                if (VideoA != null)
                    VideoA.Begin(this, true);

                isPlaying = true;
                return;

            }
            if (isPaused)
            {
                if (RectangleFadeA != null)
                    RectangleFadeA.Begin(this, true);
                if (VideoA != null)
                    VideoA.Resume(this);
                isPaused = false;
                isPlaying = true;
                return;
            }

        }

        if (isPlaying)
        {
            if (RectangleFadeBackA != null)
                RectangleFadeBackA.Begin(this, true);
            VideoA.Pause(this);
            isPlaying = false;
            isPaused = true;
            return;

        }

    }

    private void ButtonWebcam_Click(object sender, RoutedEventArgs e)
    {
        OpeningWindows.Window2 Window2 = new OpeningWindows.Window2();
        Window2.ShowDialog();
    }

    private void GTTV_promo_wmv_MediaEnded(object sender, RoutedEventArgs e)
    {
        RectangleFadeBackA.Begin(this, true);
        VideoA.Pause(this);
        isPaused = true;
        isPlaying = false;
        return;

    }
}
Kenny Bones