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; }
// (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(); }
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(); }
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; } }
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(); }
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; } } }
static void MediaClock_MediaOpened(object sender, EventArgs e) { MediaClock mc = sender as MediaClock; if (mc != null) { // Video has been opened at this point } }
public void OpenFile(string fileName) { this.mediaTimeline.Source = new Uri(fileName); MediaClock clock = this.mediaTimeline.CreateClock(); clock.Controller.Pause(); this.mediaElement.Clock = clock; }
/// <summary> /// クロックを出題用からフォロー用に切り替えます。 /// </summary> void SwitchPlayerMode() { _questionTimeLine.Duration = System.Windows.Duration.Automatic; _followClock = (MediaClock)_questionTimeLine.CreateClock(true); _followClock.Controller.Seek(_questionMediaPlayer.Position, TimeSeekOrigin.BeginTime); // Clockを切り替えます。 _questionMediaPlayer.Clock = _followClock; _followClock.Controller.Pause(); }
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(); }
private void ProgressSlider_MouseUp(object sender, MouseButtonEventArgs e) { MediaClock clock = MediaElement.Clock; if (clock != null) { TimeSpan offset = TimeSpan.FromMilliseconds(ProgressSlide.Value); clock.Controller.Seek(offset, TimeSeekOrigin.BeginTime); } _userMovingSlider = false; }
// Updates the position slider when the media time changes. private void Storyboard_Changed(object sender, EventArgs e) { ClockGroup clockGroup = sender as ClockGroup; MediaClock mediaClock = clockGroup.Children[0] as MediaClock; if (mediaClock.CurrentProgress.HasValue) { ignoreValueChanged = true; sldPosition.Value = meMediaElement.Position.TotalMilliseconds; ignoreValueChanged = false; } }
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(); }
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; }
SetClock( MediaClock clock ) { _clock._value = clock; // // We don't use _wasSet for clocks because our behavior changes dramatically // whether _value is null or not. // _clock._isSet = true; HandleStateChange(); }
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(); }
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; }
public void Stop() { _questionClock.Controller.Pause(); _questionTimeLine.Duration = System.Windows.Duration.Automatic; _followClock = (MediaClock)_questionTimeLine.CreateClock(true); _followClock.Controller.Seek(_questionMediaPlayer.Position, TimeSeekOrigin.BeginTime); _timer.Stop(); this.QuestionStopped(this, EventArgs.Empty); // Clockを切り替えます。 _questionMediaPlayer.Clock = _followClock; _followClock.Controller.Pause(); }
// (0.1.3.2)_timer.IsEnabledのチェックを追加。 public void Close() { // アンドゥの時にしか呼ばれない! _questionMediaPlayer.Clock = null; //_questionMediaPlayer.Stop(); _questionClock = null; _followClock = null; if (_timer != null && _timer.IsEnabled) { _timer.Stop(); } NotifyPropertyChanged("CurrentPosition"); _currentSongDuration = TimeSpan.Zero; NotifyPropertyChanged("Duration"); }
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(); } }
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(); }
private void Storyboard_Changed(object sender, EventArgs e) { if (endAnimationTime == null) { return; } ClockGroup clockGroup = sender as ClockGroup; if (clockGroup != null) { MediaClock mediaClock = clockGroup.Children[0] as MediaClock; if (mediaClock.CurrentProgress.HasValue) { if (mediaClock.CurrentTime >= endAnimationTime) { PlayerStoryboard.Pause(mediaElement); } } } }
/// <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); }
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(); }
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; } }
internal void SetClock(MediaClock clock) { this._clock._value = clock; this._clock._isSet = true; this.HandleStateChange(); }
public VideoDrawingExample() { // <SnippetVideoDrawingExampleInline> // // Create a VideoDrawing. // // <SnippetVideoDrawingExampleInline1> MediaPlayer player = new MediaPlayer(); // </SnippetVideoDrawingExampleInline1> // <SnippetVideoDrawingExampleInline2> player.Open(new Uri(@"sampleMedia\xbox.wmv", UriKind.Relative)); // </SnippetVideoDrawingExampleInline2> // <SnippetVideoDrawingExampleInline3> VideoDrawing aVideoDrawing = new VideoDrawing(); // </SnippetVideoDrawingExampleInline3> // <SnippetVideoDrawingExampleInline4> aVideoDrawing.Rect = new Rect(0, 0, 100, 100); // </SnippetVideoDrawingExampleInline4> // <SnippetVideoDrawingExampleInline5> aVideoDrawing.Player = player; // </SnippetVideoDrawingExampleInline5> // <SnippetVideoDrawingExampleInline6> // Play the video once. player.Play(); // </SnippetVideoDrawingExampleInline6> // </SnippetVideoDrawingExampleInline> // <SnippetRepeatingVideoDrawingExampleInline> // // Create a VideoDrawing that repeats. // // <SnippetRepeatingVideoDrawingExampleInline1> // Create a MediaTimeline. MediaTimeline mTimeline = new MediaTimeline(new Uri(@"sampleMedia\xbox.wmv", UriKind.Relative)); // Set the timeline to repeat. mTimeline.RepeatBehavior = RepeatBehavior.Forever; // </SnippetRepeatingVideoDrawingExampleInline1> // <SnippetRepeatingVideoDrawingExampleInline2> // Create a clock from the MediaTimeline. MediaClock mClock = mTimeline.CreateClock(); // </SnippetRepeatingVideoDrawingExampleInline2> // <SnippetRepeatingVideoDrawingExampleInline3> MediaPlayer repeatingVideoDrawingPlayer = new MediaPlayer(); repeatingVideoDrawingPlayer.Clock = mClock; // </SnippetRepeatingVideoDrawingExampleInline3> // <SnippetRepeatingVideoDrawingExampleInline4> VideoDrawing repeatingVideoDrawing = new VideoDrawing(); repeatingVideoDrawing.Rect = new Rect(150, 0, 100, 100); repeatingVideoDrawing.Player = repeatingVideoDrawingPlayer; // </SnippetRepeatingVideoDrawingExampleInline4> // </SnippetRepeatingVideoDrawingExampleInline> // Create a DrawingGroup to combine the drawings. DrawingGroup videoDrawings = new DrawingGroup(); videoDrawings.Children.Add(aVideoDrawing); videoDrawings.Children.Add(repeatingVideoDrawing); // // Use a DrawingImage and an Image control // to display the drawing. // DrawingImage exampleDrawingImage = new DrawingImage(videoDrawings); // Freeze the DrawingImage for performance benefits. exampleDrawingImage.Freeze(); Image anImage = new Image(); anImage.Source = exampleDrawingImage; anImage.Stretch = Stretch.None; anImage.HorizontalAlignment = HorizontalAlignment.Left; // // Place the image inside a border and // add it to the page. // Border exampleBorder = new Border(); exampleBorder.Child = anImage; exampleBorder.BorderBrush = Brushes.Gray; exampleBorder.BorderThickness = new Thickness(1); exampleBorder.HorizontalAlignment = HorizontalAlignment.Left; exampleBorder.VerticalAlignment = VerticalAlignment.Top; exampleBorder.Margin = new Thickness(10); this.Margin = new Thickness(20); this.Background = Brushes.White; this.Content = exampleBorder; }
/// <summary> /// When we've found a media clock, try to find a corresponding media /// element and attach the media clock to that element. /// </summary> private static void ApplyMediaClock( INameScope nameScope, DependencyObject containingObject, DependencyObject currentObject, string currentObjectName, MediaClock mediaClock ) { MediaElement targetMediaElement = null; if( currentObjectName != null ) { // Find the object named as the current target name. DependencyObject mentor = Helper.FindMentor(containingObject); targetMediaElement = ResolveTargetName(currentObjectName, nameScope, mentor ) as MediaElement; if( targetMediaElement == null ) { throw new InvalidOperationException(SR.Get(SRID.Storyboard_MediaElementNotFound, currentObjectName )); } } else if( currentObject != null ) { targetMediaElement = currentObject as MediaElement; } else { targetMediaElement = containingObject as MediaElement; } if( targetMediaElement == null ) { throw new InvalidOperationException(SR.Get(SRID.Storyboard_MediaElementRequired)); } targetMediaElement.Clock = mediaClock; }