private void cmdPlayCode_Click(object sender, RoutedEventArgs e)
        {
            // Create the timeline.
            // This isn't required, but it allows you to configure details
            // that wouldn't otherwise be possible (like repetition).
            MediaTimeline timeline = new MediaTimeline(new Uri("test.mpg", UriKind.Relative));

            timeline.RepeatBehavior = RepeatBehavior.Forever;

            // Create the clock, which is shared with the MediaPlayer.
            MediaClock  clock  = timeline.CreateClock();
            MediaPlayer player = new MediaPlayer();

            player.Clock = clock;

            // Create the VideoDrawing.
            VideoDrawing videoDrawing = new VideoDrawing();

            videoDrawing.Rect   = new Rect(150, 0, 100, 100);
            videoDrawing.Player = player;

            // Assign the DrawingBrush.
            DrawingBrush brush = new DrawingBrush(videoDrawing);

            this.Background = brush;

            // Start the timeline.
            clock.Controller.Begin();
        }
Example #2
0
        public override void ClearMedia()
        {
            foreach (var file in _mediaFiles)
            {
                try
                {
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                }
                catch (Exception exc)
                {
                    ShowMessage(string.Format(Resources.FileDeletionError, exc.Message));
                }
            }

            if (_mediaClock != null)
            {
                if (_mediaClock.CurrentState == System.Windows.Media.Animation.ClockState.Active)
                {
                    _mediaClock.Controller.Stop();
                }

                _mediaTimeline = null;
                _mediaClock    = null;
                _player        = null;
            }
        }
        public void Initialize()
        {
            if (this.VideoSrc != "")
            {
                if (_FrontVideoDrawing.Clock == null)
                {
                    //because our MediaElement is instantiated in code, we need to set its loaded and unloaded behavior to be manual
                    _FrontVideoDrawing.LoadedBehavior   = MediaState.Manual;
                    _FrontVideoDrawing.UnloadedBehavior = MediaState.Manual;
                    MediaTimeline mt = new MediaTimeline(new Uri((String)this.VideoSrc, UriKind.Absolute));
                    //mt.RepeatBehavior = RepeatBehavior.Forever;
                    //there are issues w/ RepeatBehavior in the Feb CTP so instead we
                    //wire up the current state invalidated event to get repeat behavior
                    mt.CurrentStateInvalidated += new EventHandler(mt_CurrentStateInvalidated);
                    MediaClock mc = mt.CreateClock();
                    _FrontVideoDrawing.Clock  = mc;
                    _FrontVideoDrawing.Width  = 5;
                    _FrontVideoDrawing.Height = 10;

                    VisualBrush   db = new VisualBrush(_FrontVideoDrawing);
                    Brush         br = db as Brush;
                    MaterialGroup mg = new MaterialGroup();
                    mg.Children.Add(new DiffuseMaterial(br));
                    GeometryModel3D gm3dFront = (GeometryModel3D)_ItemGroup.Children[0];
                    //only need to paint it one place to show up two places!
                    gm3dFront.Material = mg;
                }
            }
        }
        private void Play_Click(object sender, RoutedEventArgs e)
        {
            MediaClock clock = mediaElement.Clock;

            if (clock != null)
            {
                if (clock.IsPaused)
                {
                    clock.Controller.Resume();
                }
                else
                {
                    clock.Controller.Pause();
                }
            }
            else
            {
                if (Media == null)
                {
                    return;
                }

                MediaTimeline timeline = new MediaTimeline(Media.Uri);
                clock = timeline.CreateClock();
                clock.CurrentTimeInvalidated += Clock_CurrentTimelineInvalidated;
                mediaElement.Clock            = clock;
            }
        }
Example #5
0
        public Test()
        {
            _viewModel  = new MainWindowViewModel(DialogCoordinator.Instance);
            DataContext = _viewModel;
            InitializeComponent();
            var accent = ThemeManager.Accents.First(x => x.Name == "Purple");
            var theme  = ThemeManager.GetAppTheme("BaseLight");

            ThemeManager.ChangeAppStyle(Application.Current, accent, theme);

            TaskEx.Delay(2000);
            homepage.IsEnabled = false;

            MediaTimeline timeline = new MediaTimeline(new Uri("Wildlife.wmv", UriKind.RelativeOrAbsolute));

            clock = timeline.CreateClock();                                 //创建控制时钟

            MediaElement mediaElement = Resources["video"] as MediaElement; //得到资源

            orgin.Child        = mediaElement;
            mediaElement.Clock = clock;
            clock.Controller.Seek(new TimeSpan(0, 0, 0, 2), TimeSeekOrigin.BeginTime);//跳过固定的时间线

            clock.Controller.Stop();

            clock.Controller.Begin();

            MainTabControl.SelectionChanged += MainTabControl_SelectionChanged;
            clock.Completed += Clock_Completed;
        }
Example #6
0
        //---------------------------------------------------------//
        /// <summary>
        /// Load all the images/movies in the sample images/movies directories into the puzzle list.
        /// </summary>
        private void LoadPuzzleList()
        {
            // Load photo puzzles
            foreach (string file in Directory.GetFiles(photoPuzzlesPath, "*.jpg"))
            {
                // Load the photo
                Image img = new Image();
                img.Source = new BitmapImage(new Uri(file));

                // Add the photo to the list of possible photos
                AddElementToPuzzleList(img);
            }

            // Load video puzzles
            foreach (string file in Directory.GetFiles(videoPuzzlesPath, "*.wmv"))
            {
                // Load the video into a looping timeline
                MediaElement  video = new MediaElement();
                MediaTimeline t     = new MediaTimeline();
                t.Source         = new Uri(file);
                t.RepeatBehavior = RepeatBehavior.Forever;
                video.Clock      = t.CreateClock();

                // Start the video with audio muted.
                video.IsMuted = true;
                video.Clock.Controller.Begin();

                // Add the video to the list of possible puzzles.
                AddElementToPuzzleList(video);
            }
        }
Example #7
0
 public MusicPlayer()
 {
     //this.player = new SoundPlayer();
     this.mediaPlayer        = new MediaPlayer();
     this.mediaPlayer.Volume = 0.25;
     timeLine = new MediaTimeline();
 }
        public void CreatePlayerStoryboard(MediaElement MediaElement)
        {
            mediaElement = MediaElement;
            //NameScope.SetNameScope(this, new NameScope());
            MediaTimeline _audioTimeline = new MediaTimeline(new Uri(FilePath));
            //MediaElement _audioMediaElement = new MediaElement();
            //_audioMediaElement.Name = "audioMediaElement";
            //RegisterName(_audioMediaElement.Name, _audioMediaElement);
            //_audioMediaElement.LoadedBehavior = MediaState.Manual;
            //_audioMediaElement.UnloadedBehavior = MediaState.Manual;
            //PlayerStoryboard Storyboard.SetTargetName(_audioTimeline, _audioMediaElement.Name);
            Storyboard _packageStoryBoard = new Storyboard
            {
                SlipBehavior = SlipBehavior.Slip
            };

            _packageStoryBoard.Children.Add(_audioTimeline);
            //_packageStoryBoard.Children.Add(_imageTimeline);|
            //_packageStoryBoard.Begin(this);

            PlayerStoryboard = _packageStoryBoard;
            //PlayerStoryboard.Changed += PlayerStoryboard_Changed;
            //PlayerStoryboard.Completed += PlayerStoryboard_Completed;
            PlayerStoryboard.CurrentTimeInvalidated += Storyboard_Changed;
        }
        public override void PlaySound(string name, Action onFinish)
        {
            if (string.IsNullOrEmpty(name))
            {
                if (_mediaClock != null && _mediaClock.CurrentState == System.Windows.Media.Animation.ClockState.Active)
                {
                    _mediaClock.Controller.Stop();
                }

                return;
            }

            var source = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sounds", name);

            if (_mediaTimeline == null)
            {
                _mediaTimeline            = new MediaTimeline();
                _player                   = new MediaPlayer();
                _mediaTimeline.Completed += (sender, e) => onFinish();
            }
            else
            {
                if (_mediaClock.CurrentState == System.Windows.Media.Animation.ClockState.Active)
                {
                    _mediaClock.Controller.Stop();
                }
            }

            _mediaTimeline.Source = new Uri(source, UriKind.RelativeOrAbsolute);
            _mediaClock           = _mediaTimeline.CreateClock();
            _player.Clock         = _mediaClock;

            _mediaClock.Controller.Begin();
        }
Example #10
0
        public void Func()
        {
            MediaTimeline mtl = new MediaTimeline(new Uri(_SelectedFilePath));

            mtl.CurrentTimeInvalidated += mtl_CurrentTimeInvalidated;
            _media.Clock = mtl.CreateClock();
            _media.Clock.Controller.Resume();
        }
Example #11
0
            /// <summary>
            /// questionで指定された曲ファイルをオープンします。
            /// オープンが完了すると、MediaOpenedイベントが発生します。
            /// </summary>
            /// <param name="question"></param>
            public void Open(SweetQuestion question)
            {
                Close();

                _questionTimeLine = new MediaTimeline(new Uri(question.FileName));
                //_questionTimeLine.Completed += question_Completed;
                CurrentQuestion = question;
            }
Example #12
0
        public BuiltinMediaPlayer(IVideo video)
        {
            InitializeComponent();
            DataContext = this;
            Title       = video.Title;
            var timeline = new MediaTimeline(new Uri(MediaHelper.GetVideoPath(video), UriKind.Absolute));

            medPlayer.Clock = (MediaClock)timeline.CreateClock(true);
        }
Example #13
0
        private void LoopPlay(ref MediaPlayer player, Uri uri)
        {
            var timeLine = new MediaTimeline(uri);

            timeLine.RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever;
            var clock = timeLine.CreateClock();

            player.Clock = clock;
        }
Example #14
0
        private void btnAbspielen_Click(object sender, RoutedEventArgs e)
        {
            MediaPlayer   mediaPlayer = new MediaPlayer();
            MediaTimeline tl          = new MediaTimeline();

            tl.Source         = new Uri(abspielen);
            _clock            = tl.CreateClock();
            mediaPlayer.Clock = _clock;
            _clock.Controller.Begin();
        }
Example #15
0
        public void InitializeMedia(string path)
        {
            mediaPlayer = new MediaPlayer();
            _mTimeline  = new MediaTimeline(new Uri(path));
            _mTimeline.CurrentTimeInvalidated += MTimeline_CurrentTimeInvalidated;
            mediaPlayer.Clock = _mTimeline.CreateClock(true) as MediaClock;
            mediaPlayer.Clock.Controller.Stop();


            mediaPlayer.MediaOpened += media_MediaOpened;
        }
Example #16
0
    public Main()
    {
        InitializeComponent();
        var uri = new Uri("C:\\Test.mp3");

        MPlayer   = new MediaPlayer();
        MTimeline = new MediaTimeline(uri);
        MTimeline.CurrentTimeInvalidated += new EventHandler(MTimeline_CurrentTimeInvalidated);
        MPlayer.Clock = MTimeline.CreateClock(true) as MediaClock;
        MPlayer.Clock.Controller.Stop();
    }
Example #17
0
 private void SourceChanged(DependencyPropertyChangedEventArgs e)
 {
     if (timeLine != null)
     {
         timeLine.Source = Source;
     }
     else
     {
         timeLine = new MediaTimeline(Source);
         timeLine.CurrentTimeInvalidated += timeLine_CurrentTimeInvalidated;
     }
 }
Example #18
0
        private void OpenFile(string filepath)
        {
            editingEnabled = false;
            currentFile    = filepath;

            // Open document
            var timeline = new MediaTimeline(new Uri(filepath));

            mediaPlayer.Clock = timeline.CreateClock(true) as MediaClock;
            PlayVideo();
            //mediaPlayer.Source = new Uri(dialog.FileName);
        }
        private void WindowRoot_Loaded(object sender, RoutedEventArgs e)
        {
            this.mediaStoryboard  = (Storyboard)windowRoot.Resources["mediaStoryboard"];
            this.mediaTimeline    = (MediaTimeline)this.mediaStoryboard.Children[0];
            this.mediaFailedCount = 0;

            this.videoTrimmer.SeekerValueChanging += VideoTrimmer_SeekerValueChanging;
            this.advancedExpander.IsExpanded       = false;

            // Disable controls
            this.outputText.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            DisableAllControls();
        }
Example #20
0
 public void Play(string sound)
 {
     Dispatcher.BeginInvoke((Action)(() =>
     {
         Storyboard s = null;
         mT = new MediaTimeline(new Uri(sound));
         Storyboard.SetTarget(mT, m);
         s = new Storyboard();
         s.Children.Add(mT);
         s.Completed += S_Completed;
         s.Begin();
     }));
 }
Example #21
0
        private void meContent_Loaded(object sender, RoutedEventArgs e)
        {
            storyboard = (Storyboard)_AudioVideoPreview.Resources["sbStory"];
            MediaTimeline timeline = (MediaTimeline)storyboard.Children[0];

            timeline.Source = new Uri(mediaPath);

            if (PlayingVideo)
            {
                Play();
                Pause();
            }
        }
Example #22
0
        public void ForPlay(string url)
        {
            this.url = url;
            MediaTimeline line = new MediaTimeline(new Uri(url, UriKind.Relative));

            //line.AutoReverse = true;
            line.RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever;
            var clock = line.CreateClock();

            Media.Clock = clock;
            //Media.Open(new Uri(url, UriKind.Relative));
            Media.Volume = musicVolum;
            Media.Clock.Controller.Begin();
        }
Example #23
0
        public VideoPlayer()
        {
            InitializeComponent();
            this.PlayCommand      = new DelegateCommand(Play);
            this.PlayPauseCommand = new DelegateCommand(PlayPause);
            this.StopCommand      = new DelegateCommand(Stop);

            timeline = new MediaTimeline();
            timeline.FillBehavior = FillBehavior.Stop;
            timeline.Completed   += timeline_Completed;
            player.Clock          = clock;
            timer         = new DispatcherTimer();
            subtitle.Text = "";
        }
Example #24
0
        private void init()
        {
            MediaTimeline mTimeline = new MediaTimeline(new Uri(m_Filename, UriKind.Absolute));

            mTimeline.RepeatBehavior = RepeatBehavior.Forever;
            MediaClock  mClock = mTimeline.CreateClock();
            MediaPlayer repeatingVideoDrawingPlayer = new MediaPlayer();

            repeatingVideoDrawingPlayer.Clock = mClock;
            m_VideoDrawing.Player             = repeatingVideoDrawingPlayer;
            Z = 1;

            reconstrctDrawable();
        }
Example #25
0
        public MainWindow()
        {
            this.InitializeComponent();
            reflectorElement = reflector;
            originElement    = orgin;
            MediaTimeline timeline = new MediaTimeline(new Uri("bg_sky.mp4", UriKind.RelativeOrAbsolute));

            clock = timeline.CreateClock();//创建控制时钟

            start.IsEnabled  = false;
            pause.IsEnabled  = false;
            resume.IsEnabled = false;
            stop.IsEnabled   = false;
        }
Example #26
0
        private void OpenVideo(VideoFile video)
        {
            storyboard?.Stop(MainGrid);

            storyboard = new Storyboard();
            var timeline = new MediaTimeline(video.FileUri);

            storyboard.Children.Add(timeline);
            Storyboard.SetTarget(timeline, MediaElement);
            storyboard.CurrentTimeInvalidated += Storyboard_CurrentTimeInvalidated;

            Data.CurrentFile = video;
            storyboard.Begin(MainGrid, true);
        }
Example #27
0
        private static TimelineBase CreateMediaTimeline(GrgStoryboard argBoard,
                                                        XmlNode argNode)
        {
            Debug.Assert(null != argNode && null != argBoard);

            MediaTimeline media = new MediaTimeline(argBoard);

            if (!media.Open(argNode))
            {
                media = null;
                return(null);
            }

            return(media);
        }
Example #28
0
        private void setVideo(Uri videoUri)
        {
            MediaTimeline mTimeLine = new MediaTimeline(videoUri);

            if (videoUri.ToString().Contains("Loop"))
            {
                mTimeLine.RepeatBehavior = RepeatBehavior.Forever;
            }

            MediaClock mClock = mTimeLine.CreateClock();

            VideoPlayer.Clock = mClock;
            //VideoPlayer.Clock.Controller.Begin();
            //VideoPlayer.Clock.Controller.Pause();
        }
Example #29
0
        void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _timeline        = new MediaTimeline();
            _timeline.Source = new Uri("Gitarrensound.wav",
                                       UriKind.Relative);

            _clock = _timeline.CreateClock();
            _clock.CurrentTimeInvalidated += OnCurrentTimeInvalidated;
            _clock.Controller.Stop();

            MediaPlayer player = new MediaPlayer();

            player.MediaOpened += OnPlayerMediaOpened;
            player.Clock        = _clock;
        }
Example #30
0
 private void resetPlayer()
 {
     try
     {
         MediaElement  McMediaElement = b.FindName("McMediaElement") as MediaElement;
         MediaTimeline tl             = new MediaTimeline(new Uri(item.pathf, UriKind.Relative));
         if (McMediaElement != null)
         {
             McMediaElement.MediaOpened += (o, ex) =>
             {
                 McMediaElement.Clock.Controller.Stop();
             };
         }
     }
     catch { }
 }