Пример #1
0
            // (0.3.0)ランダムラントロ出題に対応。SeekStart、questionMediaPlayer_MediaOpenedなどを参照。
            #region *出題開始(Start)
            public void Start()
            {
                if (!CurrentQuestion.IsRandomRantro)
                {
                    // 停止位置設定を行う.
                    if (CurrentQuestion.StopPos > TimeSpan.Zero)
                    {
                        _questionTimeLine.Duration = CurrentQuestion.StopPos;
                    }
                }
                // CurrentPosition更新通知用のタイマーを動かす。
                _timer = new DispatcherTimer {
                    Interval = TimeSpan.FromMilliseconds(250)
                };
                _timer.Tick += (sender, e) => { NotifyPropertyChanged("CurrentPosition"); };

                // 再生を開始する。
                _questionClock = (MediaClock)_questionTimeLine.CreateClock(true);
                if (!CurrentQuestion.IsRandomRantro)
                {
                    _questionClock.Controller.Seek(CurrentQuestion.PlayPos, TimeSeekOrigin.BeginTime);
                }
                _questionClock.Completed  += question_Completed;
                _questionMediaPlayer.Clock = _questionClock;
                _timer.Start();
            }
Пример #2
0
        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();
        }
Пример #3
0
        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();
        }
Пример #4
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;
        }
Пример #5
0
        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;
            }
        }
        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;
                }
            }
        }
Пример #7
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);
            }
        }
Пример #8
0
        public void Func()
        {
            MediaTimeline mtl = new MediaTimeline(new Uri(_SelectedFilePath));

            mtl.CurrentTimeInvalidated += mtl_CurrentTimeInvalidated;
            _media.Clock = mtl.CreateClock();
            _media.Clock.Controller.Resume();
        }
Пример #9
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;
        }
Пример #10
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);
        }
Пример #11
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();
        }
Пример #12
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;
        }
Пример #13
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();
    }
Пример #14
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);
        }
Пример #15
0
        public override void OnApplyTemplate()
        {
            mediaElement   = (MediaElement)GetTemplateChild("mediaElement");
            timelineSlider = (Slider)GetTemplateChild("timelineSlider");

            mediaElement.Clock = timeLine.CreateClock();
            mediaElement.Clock.Controller.Pause();

            mediaElement.MediaOpened    += mediaElement_MediaOpened;
            mediaElement.MediaEnded     += mediaElement_MediaEnded;
            timelineSlider.ValueChanged += timelineSlider_ValueChanged;
            base.OnApplyTemplate();
        }
Пример #16
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;
        }
Пример #17
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();
        }
Пример #18
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();
        }
Пример #19
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;
        }
Пример #20
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();
        }
Пример #21
0
        public Window4()
        {
            InitializeComponent();

            var tl = new MediaTimeline(new Uri(@"Media/Movie1.wmv", UriKind.Relative));
            player.Clock = tl.CreateClock(true) as MediaClock;
            player.MediaOpened += (o, e) => 
            {
                slider.Maximum = player.NaturalDuration.TimeSpan.Seconds;
                player.Clock.Controller.Pause(); 
            }; 
            slider.ValueChanged += (o, e) => 
            {
                player.Clock.Controller.Seek(TimeSpan.FromSeconds(slider.Value), TimeSeekOrigin.BeginTime); 
            }; 

        }
Пример #22
0
        private void OnCurrentMusicFileNameChanged(string newValue)
        {
            var uri = new Uri(Path.Combine(CurrentMusicDirectory, newValue));

            if (MediaClock == null)
            {
                var mediaTimeLine = new MediaTimeline(uri);
                MediaClock = mediaTimeLine.CreateClock(true) as MediaClock;
                MediaClock.Controller.Stop();
            }
            else
            {
                MediaClock.Controller.Stop();
                MediaClock.Timeline.Source = uri;
                MediaClock.Controller.Stop();
            }
        }
Пример #23
0
        public Window1()
        {
            InitializeComponent();
            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();
        }
Пример #24
0
        /// <summary/>
        public Video(Rect r, string vf)
            : base(r)
        {
            videoFileName = new Uri(TrustedEnvironment.CurrentDirectory + @"\" + vf);
            video         = new MediaTimeline(videoFileName);
            video.CurrentStateInvalidated += new System.EventHandler(OnEnd);
            video.CurrentStateInvalidated += new System.EventHandler(OnBegun);
            videoClock = (MediaClock)video.CreateClock();

            //changes for MediaAPI BC - shakeels
            mediaplayer       = new MediaPlayer();
            mediaplayer.Clock = videoClock;
            //end change

            done = false;
            videoPlayingSemaphore = null;

            UpdateVisual();
        }
Пример #25
0
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            if (e.Property == SourceProperty && !Source.Equals(default(Uri)))
            {
                if (VideoFull.Clock != null)
                {
                    VideoFull.Clock.Controller.Remove();
                }

                var tl    = new MediaTimeline(Source);
                var clock = tl.CreateClock(true) as MediaClock;
                clock.CurrentTimeInvalidated += Clock_CurrentTimeInvalidated;
                clock.Completed += Clock_Completed;
                VideoFull.Clock  = clock;
            }

            if (e.Property == VolumeProperty)
            {
                VideoFull.Volume = (double)Volume / 100;
                if (Volume >= 70)
                {
                    VolumeIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.VolumeHigh;
                }

                if (Volume < 70 && Volume > 20)
                {
                    VolumeIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.VolumeMedium;
                }

                if (Volume <= 20 && Volume != 0)
                {
                    VolumeIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.VolumeLow;
                }

                if (Volume == 0)
                {
                    VolumeIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.VolumeMute;
                }
            }
            base.OnPropertyChanged(e);
        }
Пример #26
0
        private void CreateClock()
        {
            vm.Playing = @"" + files[index];
            Console.WriteLine(vm.Playing);
            var tl = new MediaTimeline(new Uri(vm.Playing));

            MediaElement.Clock = tl.CreateClock(true) as MediaClock;


            MediaElement.MediaOpened += (o, e) =>
            {
                Slider.Maximum = MediaElement.NaturalDuration.TimeSpan.TotalSeconds;
                Slider.Value   = _time;
                Window_PreviewMouseUp(null, null);
            };


            //TODO: wait 5 seconds before going further, or less
            MediaElement.Clock.Completed += NextVideo;
            MediaElement.Clock.Controller.Resume();
        }
        private void openfile_btn_Click(object sender, RoutedEventArgs e)
        {
            // Displays an OpenFileDialog so the user can select a Cursor.
            openFileDialog1        = new OpenFileDialog();
            openFileDialog1.Filter = "Video Files(*.AVI;*.MPEG;*.MPG;*.MP4)|*.AVI;*.MPEG;*.MPG;*.MP4|All files (*.*)|*.*";
            openFileDialog1.Title  = "Select a video File";

            if (openFileDialog1.ShowDialog() == true)
            {
                MediaTimeline tl = new MediaTimeline(new Uri(openFileDialog1.FileName.ToString()));

                mediaElement.Clock = tl.CreateClock(true) as MediaClock;

                mediaElement.MediaOpened += (o, ef) =>
                {
                    slider.Maximum = mediaElement.NaturalDuration.TimeSpan.TotalSeconds;
                    mediaElement.Clock.Controller.Pause();
                };

                slider.ValueChanged += (o, ef) =>
                {
                    mediaElement.Clock.Controller.Seek(TimeSpan.FromSeconds(slider.Value), TimeSeekOrigin.BeginTime);
                };

                VideoFileReader videoreader;
                videoreader = new VideoFileReader();
                // open video file
                videoreader.Open(openFileDialog1.FileName.ToString());
                framecount   = videoreader.FrameCount;
                textBox.Text = framecount.ToString();
                videoreader.Close();

                slider.IsEnabled             = true;
                gifcoverage_slider.IsEnabled = true;
                Converttogif_btn.IsEnabled   = true;

                calculateframeskip(20); // 20 % frames
            }
        }
Пример #28
0
        /// <summary>
        /// This summary has not been prepared yet. NOSUMMARY - pantal07
        /// </summary>
        public static Brush MakeVideoBrush(Uri videoUri, int seekTimeInMs)
        {
            VideoDrawing  vd = new VideoDrawing();
            MediaTimeline mt = new MediaTimeline(videoUri);
            MediaClock    mc = mt.CreateClock();

            //changes for MediaAPI BC - shakeels
            //mc.MediaOpened += new EventHandler( MediaClock_MediaOpened );
            //vd.MediaClock = mc;
            MediaPlayer mp = new MediaPlayer();

            mp.Clock        = mc;
            mp.MediaOpened += new EventHandler(MediaClock_MediaOpened);
            vd.Player       = mp;
            //end change

            vd.Rect = new Rect(0, 0, 256, 256);
            DrawingBrush db = new DrawingBrush();

            db.Drawing = vd;
            return(db);
        }
Пример #29
0
        public override void PlaySound(string name, Action onFinish)
        {
            if (string.IsNullOrEmpty(name))
            {
                StopSound();
                return;
            }

            if (!Uri.TryCreate(name, UriKind.RelativeOrAbsolute, out var uri))
            {
                return;
            }

            var source = uri.IsAbsoluteUri && uri.IsFile ? name : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sounds", name);

            if (uri.IsAbsoluteUri && uri.IsFile && !File.Exists(source))
            {
                StopSound();
                return;
            }

            if (_mediaTimeline == null)
            {
                _mediaTimeline            = new MediaTimeline();
                _player                   = new MediaPlayer();
                _mediaTimeline.Completed += (sender, e) => onFinish();
            }
            else
            {
                StopSound();
            }

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

            _mediaClock.Controller.Begin();
        }
Пример #30
0
        private void Play_Clicked(object sender, RoutedEventArgs e)
        {
            MediaClock clock = MediaElement.Clock;

            if (Play.Visibility == Visibility.Hidden)
            {
                Play.Visibility  = Visibility.Visible;
                Pause.Visibility = Visibility.Hidden;
            }
            else if (Play.Visibility == Visibility.Visible)
            {
                Play.Visibility  = Visibility.Hidden;
                Pause.Visibility = Visibility.Visible;
            }
            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_CurrentTimeInvalidated;
                MediaElement.Clock            = clock;
            }
        }