Невозможно получить раскадровку MediaElement для автореверса - PullRequest
1 голос
/ 04 марта 2009

это сводит меня с ума. Я пытаюсь получить файл WMV для автореверса после завершения воспроизведения, но он не работает. Я попытался установить автореверс Storyboard в true, но это выдает ошибку, говорящую, что

"У часов с CanSlip не может быть родителей или предков с AutoReverse, AccelerationRatio или DecelerationRatio."

Это потому, что я использую не анимацию, а видео? Как я могу достичь того же? Видео, которое я получил, работает, воспроизводит, ставит на паузу и возобновляет. Но после того, как это закончено, это просто останавливается.

У меня есть три раскадровки, одна из которых - само видео. И два, где есть анимация, которая затухает белый прямоугольник, как видео воспроизводится и останавливается.

Код выглядит так:

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;

        }



    }

}

1 Ответ

1 голос
/ 05 марта 2009

Только что нашел решение без особого кода. Прежде всего я установил для видео (MediaTimeLine) значение repeatbehaviour = forever. Затем я добавляю обработчик событий в MediaElement в «MediaEnded»

И код C # выглядит так:

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

    }

Итак, полный код C # до сих пор выглядит так:

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;

    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...