Exemple #1
0
 private static void DoPasteMarkers(TimelineWindow.TimelineState state, TrackAsset track)
 {
     if (track is ITimelineMarkerContainer)
     {
         List <TimelineMarker> list = (from x in Clipboard.GetData <EditorMarker>()
                                       select x.theMarker into x
                                       orderby x.time
                                       select x).ToList <TimelineMarker>();
         double num = 0.0;
         if (list.Count <TimelineMarker>() == 0)
         {
             num = 0.0;
         }
         else
         {
             num = list.Last <TimelineMarker>().time + 0.5;
         }
         TimelineMarker timelineMarker = null;
         foreach (TimelineMarker current in list)
         {
             if (current != null)
             {
                 if (timelineMarker != null)
                 {
                     num += current.time - timelineMarker.time;
                 }
                 MarkerModifiers.DuplicateAtTime(current, track, state.currentDirector, num);
                 timelineMarker = current;
             }
         }
     }
 }
        public static TimelineMarker DuplicateAtTime(TimelineMarker theMarker, TrackAsset track, PlayableDirector directorComponent, double newTime)
        {
            TrackAsset trackAsset = theMarker.parentTrack;

            if (track != null)
            {
                trackAsset = track;
            }
            ITimelineMarkerContainer timelineMarkerContainer = trackAsset as ITimelineMarkerContainer;
            TimelineMarker           result;

            if (timelineMarkerContainer == null || trackAsset.timelineAsset == null)
            {
                result = null;
            }
            else if (double.IsInfinity(newTime))
            {
                result = null;
            }
            else
            {
                result = timelineMarkerContainer.CreateMarker(theMarker.key, newTime);
            }
            return(result);
        }
Exemple #3
0
 private void OnMarkerReached(TimelineMarker marker)
 {
     if (MarkerReached != null)
     {
         MarkerReached(this, marker);
     }
 }
        /// <summary>
        /// Updates the time elapsed interval of the video player.
        /// </summary>
        private void UpdateTimeElapsedInterval()
        {
            if (Element.TimeElapsedInterval > 0)
            {
                var timeElapsedIntervalSpan = TimeSpan.FromSeconds(Element.TimeElapsedInterval);
                var marker = new TimelineMarker {
                    Time = timeElapsedIntervalSpan
                };
                Control.Markers.Add(marker);

                Control.MarkerReached += (sender, args) =>
                {
                    Element.OnTimeElapsed(CreateVideoPlayerEventArgs());
                    Control.Markers.Remove(args.Marker);

                    if (Element.TimeElapsedInterval > 0)
                    {
                        marker = new TimelineMarker {
                            Time = args.Marker.Time.Add(timeElapsedIntervalSpan)
                        };
                        Control.Markers.Add(marker);
                    }
                };
            }
            else
            {
                Control.Markers.Clear();
            }
        }
		internal override void AddStrongRef (IntPtr id, object value)
		{
			if (id == (IntPtr)WeakRefs.TimelineMarkerRoutedEventArgs_Marker)
				marker = (TimelineMarker) value;
			else
				base.AddStrongRef (id, value);
		}
 public TimelineMarkerGUI(TimelineMarker theMarker, TimelineAsset timeline, TimelineTrackGUI parent) : base(parent)
 {
     this.m_EditorItem = EditorItemFactory.GetEditorMarker(theMarker);
     if (parent.drawer != null)
     {
         parent.drawer.ConfigureUIEvent(this);
     }
 }
Exemple #7
0
        private double CalculateMarkerPosition(TimelineMarker timeLineMarker1, double sliderWidth)
        {
            //adjust the placement of the arrow
            double percentOfSeconds = timeLineMarker1.Time.TotalSeconds / _duration.TotalSeconds;
            double positionOfArrow  = Math.Ceiling(sliderWidth * percentOfSeconds);

            return(positionOfArrow);
        }
Exemple #8
0
        void marker_Clicked(object sender, TimelineMarker m)
        {
            double percentOfSeconds = m.Time.TotalSeconds / _duration.TotalSeconds;

            sliderTimeline.Value = percentOfSeconds;
            _media.Play();
            OnPlayClicked();
        }
Exemple #9
0
        /// <summary>
        /// Adds a marker to the current source in the <see cref="Windows.UI.Xaml.Controls.MediaElement" />.
        /// </summary>
        /// <param name="name">The marker name.</param>
        /// <param name="markerTime">The marker time.</param>
        public void AddMarker(String name, TimeSpan markerTime)
        {
            var marker = new TimelineMarker {
                Text = name, Time = markerTime
            };

            _mediaElement.Markers.Add(marker);
        }
        void MediaElement_MediaOpened(object sender, RoutedEventArgs e)
        {
            OnLoaded();

            if (SkippableOffset != null)
            {
                // create a marker for the skippable offset
                TimelineMarker skippableOffsetMarker = null;
                if (!SkippableOffset.IsAbsolute)
                {
                    skippableOffsetMarker = new TimelineMarker()
                    {
                        Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * SkippableOffset.RelativeOffset)
                    };
                }
                else
                {
                    skippableOffsetMarker = new TimelineMarker()
                    {
                        Time = SkippableOffset.AbsoluteOffset
                    };
                }
                if (skippableOffsetMarker != null)
                {
                    skippableOffsetMarker.Type = Marker_SkippableOffset;
                    mediaElement.Markers.Add(skippableOffsetMarker);
                }
            }

            adCompleted = false;
            // create markers for the quartile events
            mediaElement.Markers.Add(new TimelineMarker()
            {
                Type = Marker_FirstQuartile, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .25)
            });
            mediaElement.Markers.Add(new TimelineMarker()
            {
                Type = Marker_Midpoint, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .5)
            });
            mediaElement.Markers.Add(new TimelineMarker()
            {
                Type = Marker_ThirdQuartile, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .75)
            });

            if (MaxDuration.HasValue)
            {
                // create marker for max duration
                mediaElement.Markers.Add(new TimelineMarker()
                {
                    Type = Marker_DurationReached, Time = MaxDuration.Value
                });
            }

#if !HACK_MARKERREACHED
            mediaElement.MarkerReached += MediaElement_MarkerReached;
#endif
        }
 public static bool DuplicateEvents(TimelineMarker[] markers, PlayableDirector directorComponent)
 {
     for (int i = 0; i < markers.Length; i++)
     {
         TimelineMarker theMarker = markers[i];
         MarkerModifiers.Duplicate(theMarker, directorComponent);
     }
     return(true);
 }
Exemple #12
0
        void OnNavigationSuccess()
        {
            State = AdState.Loaded;
            if (AdLoaded != null)
            {
                AdLoaded(this, EventArgs.Empty);
            }

            if (SkippableOffset != null)
            {
                // create a marker for the skippable offset
                TimelineMarker skippableOffsetMarker = null;
                if (!SkippableOffset.IsAbsolute)
                {
                    skippableOffsetMarker = new TimelineMarker()
                    {
                        Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * SkippableOffset.RelativeOffset)
                    };
                }
                else
                {
                    skippableOffsetMarker = new TimelineMarker()
                    {
                        Time = SkippableOffset.AbsoluteOffset
                    };
                }
                if (skippableOffsetMarker != null)
                {
                    skippableOffsetMarker.Type = Marker_SkippableOffset;
                    markerHelper.Markers.Add(skippableOffsetMarker);
                }
            }

            if (SuggestedDuration.HasValue)
            {
                // create markers for the quartile events
                markerHelper.Markers.Add(new TimelineMarker()
                {
                    Type = Marker_FirstQuartile, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .25)
                });
                markerHelper.Markers.Add(new TimelineMarker()
                {
                    Type = Marker_Midpoint, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .5)
                });
                markerHelper.Markers.Add(new TimelineMarker()
                {
                    Type = Marker_ThirdQuartile, Time = TimeSpan.FromSeconds(AdDuration.TotalSeconds * .75)
                });
                // create marker for duration
                markerHelper.Markers.Add(new TimelineMarker()
                {
                    Type = Marker_DurationReached, Time = AdDuration
                });
            }

            markerHelper.MarkerReached += markerHelper_MarkerReached;
        }
Exemple #13
0
 void mediaControls_MarkerReached(object sender, TimelineMarker m)
 {
     if (_cc != null)
     {
         if (string.Compare(m.Type, "cc", StringComparison.InvariantCultureIgnoreCase) <= 0)
         {
             _cc.Update(m.Text);
         }
     }
 }
 internal override void AddStrongRef(IntPtr id, object value)
 {
     if (id == (IntPtr)WeakRefs.TimelineMarkerRoutedEventArgs_Marker)
     {
         marker = (TimelineMarker)value;
     }
     else
     {
         base.AddStrongRef(id, value);
     }
 }
 private static void SelectMarkerInInspector(ITimelineState state, TimelineMarker newEvent)
 {
     EditorWindow.FocusWindowIfItsOpen <InspectorWindow>();
     SelectionManager.Clear();
     newEvent.selected = true;
     Object[] objects = new Object[]
     {
         EditorItemFactory.GetEditorMarker(newEvent)
     };
     Selection.set_objects(objects);
 }
        private void CreateExistingMarker(string key, ITimelineMarkerContainer container, ITimelineState state)
        {
            Vector3 mousePosition = (this.trackMenuContext.clipTimeCreation != TrackDrawer.TrackMenuContext.ClipTimeCreation.Mouse) ? TimelineHelpers.sInvalidMousePosition : this.trackMenuContext.mousePosition;
            double  time          = TrackDrawer.CalculateMarkerTimeForMousePosition(container as TrackAsset, state, mousePosition);

            TimelineUndo.PushUndo(container as Object, "Create Marker");
            TimelineMarker newEvent = container.CreateMarker(key, time);

            TrackDrawer.SelectMarkerInInspector(state, newEvent);
            state.Refresh();
        }
        /// <summary>
        /// Click handler for the "Add marker" button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddMarkerButton_Click(object sender, RoutedEventArgs e)
        {
            // Add a marker to the MediaElement at 2 seconds past the current time
            TimelineMarker marker = new TimelineMarker();

            marker.Text = "Marker Fired";
            marker.Time = TimeSpan.FromSeconds(Scenario3MediaElement.Position.TotalSeconds + 2);
            Scenario3MediaElement.Markers.Add(marker);

            Scenario3Text.Text += String.Format("Marker added at time = {0:g}\n", Math.Round(Scenario3MediaElement.Position.TotalSeconds + 2, 2));
        }
        private void OnMarkerReached(TimelineMarker marker)
        {
            switch (marker.Type)
            {
            case Marker_SkippableOffset:
                AdSkippableState = true;
                mediaElement.Markers.Remove(marker);
                break;

            case Marker_FirstQuartile:
                if (AdVideoFirstQuartile != null)
                {
                    AdVideoFirstQuartile(this, EventArgs.Empty);
                }
                mediaElement.Markers.Remove(marker);
                break;

            case Marker_Midpoint:
                if (AdVideoMidpoint != null)
                {
                    AdVideoMidpoint(this, EventArgs.Empty);
                }
                mediaElement.Markers.Remove(marker);
                break;

            case Marker_ThirdQuartile:
                if (AdVideoThirdQuartile != null)
                {
                    AdVideoThirdQuartile(this, EventArgs.Empty);
                }
                mediaElement.Markers.Remove(marker);
                break;

            case Marker_DurationReached:
                if (!adCompleted)
                {
                    adCompleted = true;
                    if (AdVideoComplete != null)
                    {
                        AdVideoComplete(this, EventArgs.Empty);
                    }
                }
                mediaElement.Markers.Remove(marker);
                StopAd();
                break;

            default:
                mediaElement.Markers.Remove(marker);
                break;
            }
        }
Exemple #19
0
        public async void PopulatePacket(JsonObject subPkt, IDictionary <String, ImageData> subtitleImageMap)
        {
            await _UIDispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var hns = (long)(subPkt.GetNamedNumber("Pts") + (subPkt.GetNamedNumber("StartDisplayTime")));
                var ts  = new TimeSpan(hns);

                var marker  = new TimelineMarker();
                marker.Time = ts;
                marker.Text = subPkt.Stringify();

                SubtitlePopulatedEvent?.Invoke(this, marker, subtitleImageMap);
            });
        }
        async void PreloadAdMarker(TimelineMarker marker)
        {
            var ad = EligableAds.OfType <Advertisement>().Where(a => a.Source != null).FirstOrDefault(a => a.Id == marker.Text);

            if (ad != null)
            {
                var cancellationTokenSource = new CancellationTokenSource();
                var task = MediaPlayer.PreloadAd(ad.Source, cancellationTokenSource.Token);
                if (task != null)
                {
                    await SetOrReplaceActivePreloadOperation(new PreloadOperation(ad.Source, task, cancellationTokenSource));
                }
            }
        }
Exemple #21
0
        public static bool Contains(ITimelineItem item)
        {
            TimelineClip timelineClip = item as TimelineClip;
            bool         result;

            if (timelineClip != null)
            {
                result = SelectionManager.Contains(timelineClip);
            }
            else
            {
                TimelineMarker timelineMarker = item as TimelineMarker;
                result = (timelineMarker != null && SelectionManager.Contains(timelineMarker));
            }
            return(result);
        }
Exemple #22
0
 void PlaceTimelineMarkers()
 {
     if (m_parsedLrc != null && m_mediaElement != null)
     {
         m_mediaElement.Markers.Clear();
         for (int i = 0; i < m_parsedLrc.Sentences.Count; i++)
         {
             var marker = new TimelineMarker
             {
                 Time = new TimeSpan(m_parsedLrc.Sentences[i].Time * TimeSpan.TicksPerMillisecond),
                 Text = i.ToString()
             };
             m_mediaElement.Markers.Insert(i, marker);
         }
     }
 }
        private void MarkersButton_Click(object sender, RoutedEventArgs e)
        {
            TimelineMarker marker;

            marker = new TimelineMarker();

            marker.Text = "Marker Fired" + "\n";
            marker.Time = TimeSpan.FromSeconds(myMediaElement.Position.TotalSeconds + 2);
            myMediaElement.Markers.Add(marker);
            marker      = new TimelineMarker();
            marker.Text = "Marker Fired" + "\n";
            marker.Time = TimeSpan.FromSeconds(myMediaElement.Position.TotalSeconds + 4);
            myMediaElement.Markers.Add(marker);
            Scenario3Text.Text += String.Format("Markers added at {0:g} and {1:g}",
                                                Math.Round(myMediaElement.Position.TotalSeconds + 2, 2), Math.Round(myMediaElement.Position.TotalSeconds + 4, 2)) + "\n";
        }
Exemple #24
0
    public void Open()
    {
        World.Instance.scenesManager.cam.GetComponent <CameraInScene>().SetFilming(true);
        panel.SetActive(true);
        Utils.RemoveAllChildsIn(container);

        timelineMarker = Instantiate(timelineMarker_to_instantiate);

        timelineMarker.transform.SetParent(container);
        timelineMarker.transform.localScale = Vector2.one;
        timelineMarker.SetX(0);

        all = new List <TimeLineCharacter> ();
        timelineKeyframes = new List <TimelineKeyframe> ();

        Add();
    }
Exemple #25
0
        private void RebuildEventsGUICache(TimelineWindow.TimelineState state)
        {
            this.m_MarkerGuiCache = new List <TimelineMarkerGUI>();
            ITimelineMarkerContainer timelineMarkerContainer = base.track as ITimelineMarkerContainer;

            if (timelineMarkerContainer != null)
            {
                TimelineMarker[] markers = timelineMarkerContainer.GetMarkers();
                for (int i = 0; i < markers.Length; i++)
                {
                    TimelineMarker    theMarker = markers[i];
                    TimelineMarkerGUI item      = new TimelineMarkerGUI(theMarker, state.timeline, this);
                    this.m_MarkerGuiCache.Add(item);
                    this.m_ChildrenControls.Add(item);
                }
            }
        }
Exemple #26
0
        void theSound_MediaOpened(object sender, RoutedEventArgs e)
        {
            if (LoopTime > 0)
            {
                // set up our loop marker (this avoids gaps in loop)
                MediaElement sound = (sender as MediaElement);

                TimelineMarker marker = new TimelineMarker();
                marker.Text = "x";
                marker.Type = "y";
                marker.Time = TimeSpan.FromMilliseconds(LoopTime);

#if (!SILVERLIGHT_PHONE)
                sound.Markers.Add(marker);
#endif
            }
        }
Exemple #27
0
        public static void Add(ITimelineItem item)
        {
            TimelineClip timelineClip = item as TimelineClip;

            if (timelineClip != null)
            {
                SelectionManager.Add(timelineClip);
            }
            else
            {
                TimelineMarker timelineMarker = item as TimelineMarker;
                if (timelineMarker != null)
                {
                    SelectionManager.Add(timelineMarker);
                }
            }
        }
 private void InitializePositionTrackingEvent(PositionTrackingEvent positionTrackingEvent)
 {
     if (!positionTrackingEvent.PositionPercentage.HasValue || (positionTrackingEvent.PositionPercentage.Value > 0 && positionTrackingEvent.PositionPercentage.Value < 1))
     {
         var timelineMarker = new TimelineMarker();
         timelineMarker.Type = MarkerType_TrackingEvent;
         timelineMarker.Text = Guid.NewGuid().ToString();
         if (positionTrackingEvent.PositionPercentage.HasValue)
         {
             timelineMarker.Time = TimeSpan.FromSeconds(positionTrackingEvent.PositionPercentage.Value * MediaPlayer.Duration.TotalSeconds);
         }
         else
         {
             timelineMarker.Time = positionTrackingEvent.Position;
         }
         MediaPlayer.Markers.Add(timelineMarker);
         activeMarkers.Add(timelineMarker.Text, positionTrackingEvent);
     }
 }
Exemple #29
0
 public void ProcessParsedMarkerCollection()
 {
     if (_externalMarkerData.Count > 0)
     {
         foreach (MarkerData data in _externalMarkerData)
         {
             if (data.Enabled)
             {
                 TimelineMarker timeLineMarker1 = new TimelineMarker();
                 timeLineMarker1.Text = data.Text;
                 timeLineMarker1.Time = data.Time;
                 //NOTE: in SL2 Beta 2 if type is not set the app crashed
                 timeLineMarker1.Type = data.Type;
                 _media.Markers.Add(timeLineMarker1);
             }
         }
         PlaceMarkers();
         //set a handler to control how the marker popup gets displayed
         _media.MarkerReached += new TimelineMarkerRoutedEventHandler(_media_MarkerReached);
     }
 }
        bool PlayAdMarker(TimelineMarker marker)
        {
            var ad = Advertisements.OfType <MidrollAdvertisement>().Where(a => a.Source != null).FirstOrDefault(a => a.Id == marker.Text);

            if (ad != null)
            {
                if (EligableAds.Contains(ad))
                {
                    TimeSpan?syncToPosition = null;
                    if (ad.Duration > TimeSpan.Zero)
                    {
                        syncToPosition = ad.Time.Add(ad.Duration);
                    }
                    PlayAd(ad, syncToPosition);
                    return(true);
                }
                else if (ad.Duration > TimeSpan.Zero)
                {
                    SyncMainContent(ad.Time.Add(ad.Duration));
                }
            }
            return(false);
        }
Exemple #31
0
        public static void ConvertSrtToTimlineMarker(string srt, MediaPlayer me)
        {
            TimelineMarker timelineMarker = new TimelineMarker();
            var            pattern        = new string[1] {
                "\r\n\r\n"
            };
            var shortPattern = new string[1] {
                "\r\n"
            };
            var timeSplitter = new string[1] {
                " --> "
            };
            var srtSplit = srt.Split(pattern, StringSplitOptions.None);

            foreach (string s in srtSplit)
            {
                try
                {
                    var lines       = s.Split(shortPattern, StringSplitOptions.None);
                    var timeStrings = lines[1].Split(timeSplitter, StringSplitOptions.None);
                    var start       = timeStrings[0];
                    var end         = timeStrings[1];
                    var text        = String.Join(Environment.NewLine, lines.Skip(2));

                    TimelineMarker tlm = new TimelineMarker();
                    tlm.Time = TimeSpan.Parse(start.Replace(',', '.'));
                    tlm.Text = text;
                    me.Markers.Add(tlm);
                    TimelineMarker tlEnd = new TimelineMarker();
                    tlEnd.Time = TimeSpan.Parse(end.Replace(',', '.'));
                    tlEnd.Text = "";
                    me.Markers.Add(tlEnd);
                }
                catch { }
            }
        }
		internal TimelineMarkerRoutedEventArgs (IntPtr raw, bool dropref) : base (raw, dropref)
		{
			this.marker = NativeDependencyObjectHelper.FromIntPtr (NativeMethods.timeline_marker_routed_event_args_get_marker (raw)) as TimelineMarker;
		}
 public void CaptionFired(TimelineMarker Caption)
 {
 }
        public void ProcessParsedMarkerCollection()
        {
            if (_externalMarkerData.Count > 0)
            {
                foreach (MarkerData data in _externalMarkerData)
                {
                    if (data.Enabled)
                    {
                        TimelineMarker timeLineMarker1 = new TimelineMarker();
                        timeLineMarker1.Text = data.Text;
                        timeLineMarker1.Time = data.Time;
                        //NOTE: in SL2 Beta 2 if type is not set the app crashed
                        timeLineMarker1.Type = data.Type;
                        _media.Markers.Add(timeLineMarker1);
                    }
                }
                PlaceMarkers();
                //set a handler to control how the marker popup gets displayed
                _media.MarkerReached += new TimelineMarkerRoutedEventHandler(_media_MarkerReached);

            }
        }
Exemple #35
0
		public void MarkersTest ()
		{
			MediaElement mel = new MediaElement ();
			AssertFailedException ex = null;
			TimelineMarker marker1 = new TimelineMarker ();
			TimelineMarker marker2 = new TimelineMarker ();
			int markers_reached = 0;
			marker1.Text = "marker1";
			marker1.Type = "type1";
			marker1.Time = TimeSpan.FromSeconds (1);
			marker2.Text = "marker2";
			marker2.Type = "type2";
			marker2.Time = TimeSpan.FromSeconds (1.1);
			mel.Name = "mel";
			mel.AutoPlay = true;

			TestPanel.Children.Add (mel);

			mel.MediaFailed += new EventHandler<ExceptionRoutedEventArgs> (delegate (object sender, ExceptionRoutedEventArgs e)
			{
				ex = new AssertFailedException ("Media should open successfully");
			});
			mel.MediaOpened += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e)
			{
				mel.Markers.Add (marker2);
				mel.Markers.Add (marker1);
				if (mel.Markers [0] != marker1)
					ex = new AssertFailedException ("mel.Markers [0] != markers1");
				if (mel.Markers [1] != marker2)
					ex = new AssertFailedException ("mel.Markers [1] != markers2");
			});
			mel.MarkerReached += new TimelineMarkerRoutedEventHandler (delegate (object sender, TimelineMarkerRoutedEventArgs e)
			{
				markers_reached++;
				switch (markers_reached) {
				case 1:
					if (marker1 == e.Marker)
						ex = new AssertFailedException ("Got marker1 back, not a copy");
					break;
				case 2:
					if (marker2 == e.Marker)
						ex = new AssertFailedException ("Got marker2 back, not a copy");
					break;
				}
				if (mel.Markers [0] != marker1)
					ex = new AssertFailedException ("mel.Markers [0] != markers1");
				if (mel.Markers [1] != marker2)
					ex = new AssertFailedException ("mel.Markers [1] != markers2");
			});
			mel.MediaEnded += new RoutedEventHandler (delegate (object sender, RoutedEventArgs e)
			{
				ex = new AssertFailedException ("MediaEnded: Test should finish before media ends");
			});
			mel.Source = new Uri ("/moon-unit;component/timecode-long-with-audio.wmv", UriKind.Relative);

			EnqueueConditional (() => ex != null || markers_reached == 2);
			Enqueue (() =>
			{
				if (ex != null)
					throw ex;
			});
			EnqueueTestComplete ();
		}
 void marker_Clicked(object sender, TimelineMarker m)
 {
     double percentOfSeconds = m.Time.TotalSeconds / _duration.TotalSeconds;
     sliderTimeline.Value = percentOfSeconds;
     _media.Play();
     OnPlayClicked();
 }
 private double CalculateMarkerPosition(TimelineMarker timeLineMarker1, double sliderWidth)
 {
     //adjust the placement of the arrow
     double percentOfSeconds = timeLineMarker1.Time.TotalSeconds / _duration.TotalSeconds;
     double positionOfArrow = Math.Ceiling(sliderWidth * percentOfSeconds);
     return positionOfArrow;
 }
 private void OnMarkerReached(TimelineMarker marker)
 {
     if (MarkerReached != null)
     {
         MarkerReached(this, marker);
     }
 }
 internal MarkerReachedEventArgs(TimelineMarker marker)
 {
     Marker = marker;
 }
        private void AddMarkers(IAsyncResult argAR)
        {
            try {
                if (!Deployment.Current.Dispatcher.CheckAccess())
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() => AddMarkers(argAR));
                }

                foreach (SegmentInfo segmentInfo in this.element.ManifestInfo.Segments)
                {
                    foreach (StreamInfo streamInfo in segmentInfo.SelectedStreams)
                    {
                        if (streamInfo.UniqueId == ((string)argAR.AsyncState))
                        {
                            foreach (TrackInfo trackInfo in streamInfo.SelectedTracks)
                            {
                                ChunkResult chunkResult = trackInfo.EndGetChunk(argAR);

                                if (chunkResult.Result == ChunkResult.ChunkResultState.Succeeded && currentTextTrack != null)
                                {
                                    System.Text.Encoding enc = System.Text.Encoding.UTF8;
                                    int length = (int)chunkResult.ChunkData.Length;
                                    byte[] rawData = new byte[length];
                                    chunkResult.ChunkData.Read(rawData, 0, length);
                                    String text = enc.GetString(rawData, 0, rawData.Length);
                                    XElement xElem = XElement.Parse(text);
                                    XElement bodyElem = xElem.Elements().FirstOrDefault(e => e.Name.LocalName == "body");

                                    //first received chunk - notify js
                                    if (!textTrackLoaded)
                                    {
                                        XElement copyElement = new XElement(xElem);
                                        XElement copyBodyElem = copyElement.Elements().FirstOrDefault(e => e.Name.LocalName == "body");
                                        //we can't send the body elements, they are causing "Eval" exception
                                        copyBodyElem.RemoveAll();
                                        SourceEventArgs args = new SourceEventArgs(getCurrentTextIndex());
                                        args.Text = copyElement.ToString();
                                        TextTrackLoaded(this, args);
                                        textTrackLoaded = true;
                                    }

                                    //Get the caption language
                                    string langName = "";
                                    currentTextTrack.Attributes.TryGetValue("Name", out langName);

                                    //Fix for TTML where div contains begin and end values instead of paragraph node
                                    int segId = 0;
                                    //Get all div under the body node
                                    IEnumerable<XElement> divElements =
                                            from div in bodyElem.Descendants()
                                            where div.Name.LocalName == "div"
                                            select div;
                                    //Fix alogorithem:
                                    //1. Iterate over each div.
                                    //2. Find each begin and end values.
                                    //3. Aggregate over each child of a div, concat it text value.
                                    //4. Create a new paragraph element with the div begin and end attributes.
                                    //5. Clear all the attribute and elements of the original div and replace with new paragraph.
                                    foreach (XElement divElem in divElements) {
                                        XAttribute begin = divElem.Attributes().FirstOrDefault(e => e.Name.LocalName == "begin");
                                        XAttribute end = divElem.Attributes().FirstOrDefault(e => e.Name.LocalName == "end");

                                        if (begin != null)
                                        {
                                            IEnumerable<string> textSegs =
                                                from seg in divElem.Descendants()
                                                where seg.Name.LocalName == "p"
                                                select (string)seg;

                                            string str = textSegs.Aggregate((x, y) => x + "<br/>" + y);

                                            XElement pElem = divElem.Elements().FirstOrDefault(e => e.Name.LocalName == "p");
                                            XAttribute region = pElem.Attributes().FirstOrDefault(e => e.Name.LocalName == "region");

                                            divElem.RemoveAll();

                                            XAttribute idAttr = new XAttribute("id", "p" + segId);
                                            XElement newP = new XElement("p", begin, end, region, idAttr);
                                            newP.Value = str;
                                            divElem.Add(newP);
                                            segId++;
                                        }
                                    }
                                    //Turn each caption line to a media marker
                                    foreach (XElement el in bodyElem.Elements())
                                    {
                                        IEnumerable<XElement> pSegs =
                                                from p in el.Descendants()
                                                where p.Name.LocalName == "p"
                                                select p;

                                        foreach (XElement pSeg in pSegs)
                                        {
                                            TimelineMarker newMarker = new TimelineMarker();
                                            //Create discrete marker points for each segment
                                            pSeg.Add(new XAttribute("timestamp", chunkResult.Timestamp.TotalSeconds.ToString()));
                                            newMarker.Text = pSeg.ToString();
                                            newMarker.Type = langName;
                                            XAttribute begin = pSeg.Attribute("begin");
                                            if (begin.Value != null)
                                            {
                                                newMarker.Time = chunkResult.Timestamp + TimeSpan.Parse(begin.Value);
                                                this.element.Markers.Add(newMarker);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }catch(Exception ex)
            {
                logger.info("Error occur while trying to add marker:" + ex.Message);
            }
        }
        /// <summary>
        /// Parse our text streams
        /// </summary>
        /// <param name="manifest">the xml we are parsing</param>
        /// <param name="manifestInfo">the manifest info object we are returning</param>
        private static void ParseTextStream(XmlReader manifest, ManifestInfo manifestInfo)
        {
            // Parse all of the entries
            while (manifest.Read())
            {
                if (manifest.Name.Equals("Marker"))
                {
                    string markerTime = manifest.GetAttribute("Time");
                    string markerValue = manifest.GetAttribute("Value");

                    TimelineMarker marker = new TimelineMarker();
                    marker.Type = MarkerType;
                    marker.Time = new TimeSpan((long)Convert.ToUInt64(markerTime, CultureInfo.InvariantCulture));
                    marker.Text = markerValue;
                    manifestInfo.Markers.Add(marker);
                }
                else if (manifest.Name.Equals("ScriptCommand"))
                {
                    string markerTime = manifest.GetAttribute("Time");
                    string markerType = manifest.GetAttribute("Type");
                    string markerCommand = manifest.GetAttribute("Command");

                    TimelineMarker marker = new TimelineMarker();
                    marker.Type = markerType;
                    marker.Time = new TimeSpan((long)Convert.ToUInt64(markerTime, CultureInfo.InvariantCulture));
                    marker.Text = markerCommand;
                    manifestInfo.Markers.Add(marker);
                }
                else if (manifest.Name.Equals("StreamIndex"))
                {
                    break;
                }
            }
        }
Exemple #42
0
        private void setSubs()
        {
            //MessageBox.Show(PivotPage1.napisy);

            //TimelineMarkerCollection marks =  new TimelineMarkerCollection();

            string[] x = new string[1] { "\n" };
            string[] lines = PivotPage1.napisy.Split(x, StringSplitOptions.RemoveEmptyEntries);

            foreach (string i in lines)
            {
                TimelineMarker uno = new TimelineMarker();
                TimelineMarker dos = new TimelineMarker();
                // RegEx

                //MessageBox.Show(i);

                Regex reg = new Regex(@"\[\d*\]");
                MatchCollection matches = reg.Matches(i);
                if (matches.Count == 2)
                {
                    string time_p = matches[0].Value.Substring(1, matches[0].Value.Length - 2);
                    string time_k = matches[1].Value.Substring(1, matches[1].Value.Length - 2);

                    string text = i.Substring(time_p.Length + time_k.Length + 4);

                    //MessageBox.Show("Tekst: " + text + "\n\nP: " + time_p + "\n\nK: " + time_k);

                    uno.Text = text;
                    dos.Text = "";

                    //double time_p_d = Double.Parse(time_p) / 23.976;
                    //double time_k_d = Double.Parse(time_k) / 23.976;
                    float time_p_d = float.Parse(time_p) / 10;
                    float time_k_d = float.Parse(time_k) / 10;
                    int m_p = (int)(time_p_d / 60);
                    time_p_d = time_p_d - 60 * m_p;
                    int m_k = (int)(time_k_d / 60);
                    time_k_d = time_k_d - 60 * m_k;
                    int h_p = m_p / 60;
                    m_p = m_p - 60 * h_p;
                    int h_k = m_k / 60;
                    m_k = m_k - 60 * h_k;

                    string time_p_s = h_p.ToString() + ":" + m_p.ToString() + ":" + time_p_d.ToString();
                    string time_k_s = h_k.ToString() + ":" + m_k.ToString() + ":" + time_k_d.ToString();

                    //string last = lines.Last();

                    //if(i==lines.Last()) { MessageBox.Show("P: " + time_p_s + "\n\nK: " + time_k_s + "\n\nLine: " + i); break;}

                    try
                    {
                        uno.Time = TimeSpan.Parse(time_p_s);
                        dos.Time = TimeSpan.Parse(time_k_s);
                    }
                    catch (Exception e) { MessageBox.Show(e.Message + "\n\nP: " + time_p_s + "\n\nK: " + time_k_s); }
                    //uno.Type = "subs";
                    //dos.Type = "subs";

                    //marks.Add(uno);
                    //marks.Add(dos);
                    try
                    {
                        //MessageBox.Show("Przed dodaniem");

                        myPlayer.Markers.Add(uno);
                        myPlayer.Markers.Add(dos);

                        //MessageBox.Show("Po dodaniu");
                    }
                    catch (Exception e) { MessageBox.Show(e.Message); }
                }
                else
                {
                    MessageBox.Show("Błedny format napisów. Liczba: " + matches.Count.ToString());

                    string tmp = "";
                    foreach (Match j in matches) tmp += j.Value + "\n";

                    MessageBox.Show(tmp);

                    break;
                }

            }

            //MessageBox.Show("Po dodaniu wszystkich");
        }
 private void media_MediaOpened(object sender, RoutedEventArgs e)
 {
     this.timelineSlider.Minimum = 0;
     this.timelineSlider.Maximum = 100;
     double seconds = this.media.NaturalDuration.TimeSpan.TotalSeconds;
     for (int i = (int)this.timelineSlider.Minimum; i < (int)this.timelineSlider.Maximum; i++)
     {
         TimelineMarker marker = new TimelineMarker();
         double time = seconds / this.timelineSlider.Maximum * i;
         marker.Time = new TimeSpan(0, 0, (int)time);
         marker.Text = "marker";
         marker.Type = "marks";
         this.media.Markers.Add(marker);
     }
 }
        // MediaOpenedのキック時
        // 開かれた動画にマーカーを付ける
        private void movie_MediaOpened(object sender, RoutedEventArgs e)
        {
            // 動画の読み込み時にスライダ操作
            Volume.Value = 1.0;

            // 前の動画のマーカーをクリア
            movie.Markers.Clear();
            markers.Children.Clear();

            var i = 0;
            foreach (var value in MediaData.media[movie_index].sync)
            {
                var valueT = TimeSpan.Parse(value.time);
                if (movie.NaturalDuration.TimeSpan > valueT)
                {
                    // TimelineMarkerの定義
                    var TLMarker = new TimelineMarker
                    {
                        Time = valueT,
                        Text = "enabled"
                    };
                    movie.Markers.Add(TLMarker);

                    // 同期ポイントボタンの定義
                    var image = new Image
                    {
                        Source = new BitmapImage(new Uri("../image/marker.png", UriKind.Relative)),
                        Margin = new Thickness(-10, 0, 0, 0),
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Height = 20,
                        Width = 20,
                        Tag = i
                    };
                    Canvas.SetLeft(image, valueT.TotalSeconds / movie.NaturalDuration.TimeSpan.TotalSeconds * 320);
                    Grid.SetColumn(image, 0);
                    Grid.SetRow(image, 3);
                    Grid.SetColumnSpan(image, 3);

                    // 同期ポイントボタンを押したら
                    // 対応するmovie1とmovie2の同期ポイントに同期
                    image.MouseLeftButtonDown += new MouseButtonEventHandler((object _s, MouseButtonEventArgs _e) =>
                    {
                        foreach (var valueL in MediaData.movieList)
                        {
                            valueL.currentPlayer.movie.Position = valueL.currentPlayer.movieEx.Position
                                = TimeSpan.Parse(MediaData.media[valueL.currentPlayer.movie_index].sync[(int)image.Tag].time);

                            if (valueL.currentPlayer.sb.GetCurrentState() == ClockState.Stopped)
                            {
                                valueL.currentPlayer.sb.Begin();
                                valueL.currentPlayer.sb.Pause();
                            }
                            valueL.currentPlayer.sb.SeekAlignedToLastTick(valueL.currentPlayer.movie.Position);
                        }
                    });
                    image.MouseWheel += new MouseWheelEventHandler((object _s, MouseWheelEventArgs _e) =>
                    {
                        switch (movie.Markers[(int)image.Tag].Text)
                        {
                            case "enabled":
                                foreach (var valueL in MediaData.movieList)
                                {
                                    (valueL.currentPlayer.markers.Children[(int)image.Tag] as Image).Source =
                                        new BitmapImage(new Uri("../image/marker_disabled.png", UriKind.Relative));
                                    valueL.currentPlayer.movie.Markers[(int)image.Tag].Text = "disabled";
                                }
                                break;
                            //case "disabled":
                            //    (movie1Markers.Children[(int)image.Tag] as Image).Source =
                            //        new BitmapImage(new Uri("image/marker.png", UriKind.Relative));
                            //    movie1.Markers[(int)image.Tag].Text = "enabled";
                            //    (movie2Markers.Children[(int)image.Tag] as Image).Source =
                            //        new BitmapImage(new Uri("image/marker.png", UriKind.Relative));
                            //    movie2.Markers[(int)image.Tag].Text = "enabled";
                            //    break;
                        }
                    });
                    markers.Children.Add(image);
                    i++;
                }
            }
        }
 public void CaptionFired(TimelineMarker Caption)
 {
     CaptionBlock.Text = Caption.Text;
 }
Exemple #46
0
 /// <summary>
 /// Handles the MediaOpened event of the player, raised when a new source has been set and Play()
 /// has been called.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e"></param>
 private void Player_MediaOpened(object sender, RoutedEventArgs e)
 {
     if(_resetPlayerPosition)
     {
         //Can only set positions and markers in this event for playback to perform properly.
         TimelineMarker marker = new TimelineMarker();
         marker.Time = _currentPhrase.Audio.ClipEnd;
         marker.Text = "StopMarker";
         marker.Type = "StopMarkerType";
         _player.Markers.Add(marker);
         _player.Position = _currentPhrase.Audio.ClipStart;
         if(_playOnMediaLoad)
         {
             _player.Play();
         }
     }
 }