3

必要なのは、PositionWPF のMediaElementコントロールにプロパティを設定することです。しかし、ビデオを再生すると (何らかのアニメーションを介して、Play()または何らかのアニメーションを介してOpacity) まったく機能しません。00:00:00 の時刻が表示されていますが、00:00:05 に設定されていると思います。

位置の値をハードコーディングしましたが、まったく機能しません。

念のため、すべてのコードを配置して、アニメーション ロジック全体を確認できるようにします。

どんな手掛かり?

  public partial class CrossFadeTransition : UserControl
    {
        DoubleAnimation _doubleAnimationFrontPlayer = new DoubleAnimation();
        DoubleAnimation _doubleAnimationBackPlayer = new DoubleAnimation();

        Storyboard _sb1 = new Storyboard();
        Storyboard _sb2 = new Storyboard();

        public TimeSpan Duration = TimeSpan.FromSeconds(2);
        public Dictionary<string, Position2D> PlayerPosition { set; get; }

        public CrossFadeTransition()
        {
            InitializeComponent();

            Player1.LoadedBehavior = MediaState.Manual;
            Player1.UnloadedBehavior = MediaState.Stop;

            Player2.LoadedBehavior = MediaState.Manual;
            Player2.UnloadedBehavior = MediaState.Stop;

            PlayerPosition = new Dictionary<string, Position2D>();

            PlayerPosition.Add("Player1", Position2D.Front);
            PlayerPosition.Add("Player2", Position2D.Back);

        }
        Position2D positionPlayer1;
        Position2D positionPlayer2;

        public void Stop()
        {
            if (Player1.IsEnabled)
                Player1.Stop();

            if (Player2.IsEnabled)
                Player2.Stop();

        }

        public void Start(Uri uri, int? position)
        {
            try
            {
                positionPlayer1 = PlayerPosition["Player1"];

                positionPlayer2 = PlayerPosition["Player2"];

                if (positionPlayer1 == Library.Position2D.Back)
                {
                    Player1.Source = uri;
                    if (Player1.IsEnabled)
                        Player1.Stop();

                    Player1.Position = TimeSpan.FromSeconds(5); // IT IS NOT WORKING !!!

                    Player1.Play();

                }

                if (positionPlayer2 == Library.Position2D.Back)
                {
                    Player2.Source = uri;
                    if (Player2.IsEnabled)
                        Player2.Stop();

                    Player2.Position = TimeSpan.FromSeconds(5); // IT IS NOT WORKING !!!

                    Player2.Play();

                }



                _sb1.Children.Clear();
                _sb2.Children.Clear();



                if (positionPlayer1 == Position2D.Front)
                {
                    _doubleAnimationFrontPlayer.From = 1;
                    _doubleAnimationFrontPlayer.To = 0;
                    _doubleAnimationFrontPlayer.Duration = new Duration(Duration);

                    PlayerPosition["Player1"] = Position2D.Back;
                }
                else if (positionPlayer1 == Position2D.Back)
                {
                    _doubleAnimationFrontPlayer.From = 0;
                    _doubleAnimationFrontPlayer.To = 1;
                    _doubleAnimationFrontPlayer.Duration = new Duration(Duration);

                    PlayerPosition["Player1"] = Position2D.Front;
                }

                if (positionPlayer2 == Position2D.Front)
                {
                    _doubleAnimationBackPlayer.From = 1;
                    _doubleAnimationBackPlayer.To = 0;
                    _doubleAnimationBackPlayer.Duration = new Duration(Duration);

                    PlayerPosition["Player2"] = Position2D.Back;
                }
                else if (positionPlayer2 == Position2D.Back)
                {
                    _doubleAnimationBackPlayer.From = 0;
                    _doubleAnimationBackPlayer.To = 1;
                    _doubleAnimationBackPlayer.Duration = new Duration(Duration);

                    PlayerPosition["Player2"] = Position2D.Front;
                }

                _sb1.Children.Add(_doubleAnimationFrontPlayer);
                Storyboard.SetTargetProperty(_doubleAnimationFrontPlayer, new PropertyPath("(Panel.Opacity)"));
                Storyboard.SetTarget(_doubleAnimationFrontPlayer, Player1);
                _sb1.Completed += _sb1_Completed;
                _sb1.Begin();

                //
                _sb2.Children.Add(_doubleAnimationBackPlayer);
                Storyboard.SetTargetProperty(_doubleAnimationBackPlayer, new PropertyPath("(Panel.Opacity)"));
                Storyboard.SetTarget(_doubleAnimationBackPlayer, Player2);
                _sb2.Completed += _sb2_Completed;
                _sb2.Begin();

            }
            catch (Exception)
            {

                throw;
            }
        }

        void _sb2_Completed(object sender, EventArgs e)
        {
            _sb2.Completed -= _sb2_Completed;

            Debug.WriteLine("Player2 COMPLETED " + DateTime.Now.TimeOfDay);

            if (positionPlayer2 == Position2D.Front)
            {
                Player2.Stop();
            }
        }

        void _sb1_Completed(object sender, EventArgs e)
        {
            _sb1.Completed -= _sb1_Completed;

            Debug.WriteLine("Player1 COMPLETED " + DateTime.Now.TimeOfDay);
            if (positionPlayer1 == Position2D.Front)
            {
                Player1.Stop();
            }
        }
    }

私は次のようにしようとしました

Player2.Play();
Player2.Pause();
Player2.Position = TimeSpan.FromSeconds(5); // IT IS NOT WORKING !!!
Player2.Play();

しかし、喜びはありません...

4

1 に答える 1

5

私はいくつかの解決策を見つけました。最初のビデオ フレームが表示されることがあるため、完全に理想的ではありませんが、少なくとも機能しています。

  1. new を適用できるイベントが必要Positionです。

    void Player2_MediaOpened(object sender, RoutedEventArgs e)
    {
         Player2.Position = new TimeSpan(0, 0, 7);
    }
    
    void Player1_MediaOpened(object sender, RoutedEventArgs e)
    {
        Player1.Position = new TimeSpan(0, 0, 7);
    }
    
  2. このまま締め切ら ないといけないMediaelement

    Player1.Stop();
    Player1.Close();
    Player1.Source = uri;
    Player1.Play();
    

楽しむ!(ビール)

于 2013-02-22T17:06:39.690 に答える