public void SeekBySeconds(int seconds)
        {
            TimeSpan newPosition;
            if (seconds > 0)
            {
                TimeSpan addSeconds = new TimeSpan(0, 0, seconds);
                newPosition = MediaPlayer.Position.Add(addSeconds);
            }
            else
            {
                TimeSpan subtractSeconds = new TimeSpan(0, 0, (seconds * -1)); //make it a positive number again
                newPosition = MediaPlayer.Position.Subtract(subtractSeconds);
            }
            Duration duration = MediaPlayer.NaturalDuration;

            if ((duration.HasTimeSpan && newPosition < duration.TimeSpan) && newPosition > TimeSpan.Zero)
            {
                MediaPlayer.Position = newPosition;

                if (MediaPlayer.Markers.Count > 0)
                {
                    var currentEndTimeMaker = MediaPlayer.Markers[0].Time;
                    if (newPosition > currentEndTimeMaker)
                    {
                        MediaPlayer.Markers.Clear();
                        MainUI.SliderControl.HasSeekedBeyondEnd = true;
                    }
                }
                else
                {
                    MainUI.SliderControl.HasSeekedBeyondEnd = false;
                }

                var seekEvent = new Event
                {
                    Name = "Seek",
                    EventArgs = new List<EventArg>() { { new EventArg() { Name = "NewPosition", Value = newPosition.ToString() } } }
                };
                MainUI.Controller.SendEvent(seekEvent);
            }
        }
 private void HandleGetSourceAndPositionCallback(Event callback)
 {
     if (callback.EventArgs != null && callback.EventArgs.ContainsKey("CallbackId")
         && callback.EventArgs.ContainsKey("Position") && callback.EventArgs.ContainsKey("Source")
         && callback.EventArgs.ContainsKey("NodeId"))
     {
         string callbackId = callback.EventArgs["CallbackId"];
         string source = callback.EventArgs["Source"];
         string nodeId = callback.EventArgs["NodeId"];
         switch (callbackId)
         {
             case "StartPosition":
                 TimeSpan startPosition = TimeSpan.Parse(callback.EventArgs["Position"]);
                 SaveMediaInformation(nodeId, source, callbackId, startPosition);
                 break;
             case "EndPosition":
                 TimeSpan endPosition = TimeSpan.Parse(callback.EventArgs["Position"]);
                 SaveMediaInformation(nodeId, source, callbackId, endPosition);
                 break;
             default:
                 break;
         }
     }
 }
 private void HandleReplayingLastNodeEvent(Event receivedEvent)
 {
     //if (ViewManager != null && ViewManager.CurrentView != null && ViewManager.CurrentView.NodeRenderers != null
     //    && receivedEvent.EventArgs != null && receivedEvent.EventArgs.ContainsKey("NodeId"))
     //{
     //    Guid nodeId = Guid.Empty;
     //    if (Guid.TryParse(receivedEvent.EventArgs["NodeId"], out nodeId))
     //    {
     //        NodeRenderer playingNode = ViewManager.CurrentView.NodeRenderers[nodeId];
     //        {
     //            playingNode.SetIsPlaying(true);
     //            playingNode.ResetMediaIcon(true);
     //        }
     //    }
     //}
 }
 private void HandleSeekEvent(Event receivedEvent)
 {
     //if (receivedEvent.EventArgs != null && receivedEvent.EventArgs.ContainsKey("NewPosition"))
     //{
     //    if (ViewManager != null && ViewManager.CurrentView != null && ViewManager.CurrentView.NodeRenderers != null)
     //    {
     //        TimeSpan newPosition = TimeSpan.MinValue;
     //        if (TimeSpan.TryParse(receivedEvent.EventArgs["NewPosition"], out newPosition))
     //        {
     //            foreach (NodeRenderer nodeRenderer in ViewManager.CurrentView.NodeRenderers.Values)
     //            {
     //                if (nodeRenderer.ResetMediaIcon(newPosition))
     //                {
     //                    break;
     //                }
     //            }
     //        }
     //    }
     //}
 }
        private void HandledCurrentStateChanged(Event receivedEvent)
        {
            if (!HasVideo)
            {
                HasVideo = true;
            }

            if (receivedEvent.EventArgs != null && receivedEvent.ContainsEventArg("State"))
            {
                string state = receivedEvent.GetEventArgValue("State");

                if (receivedEvent.ContainsEventArg("NodeId"))
                {
                    string viewModelIdAsString = receivedEvent.GetEventArgValue("NodeId");

                    if (!string.IsNullOrEmpty(state) && !string.IsNullOrEmpty(viewModelIdAsString))
                    {
                        var neutralisedState = state.ToLower();
                        var viewModelId = new Guid(viewModelIdAsString);

                        if (ViewModels.ContainsKey(viewModelId))
                        {
                            VideoInfo viewModelVideoInfo = ViewModels[viewModelId];

                            switch (neutralisedState)
                            {
                                case "idle":
                                    _isChangedByController = true;
                                    viewModelVideoInfo.Status = VideoState.Pause;
                                    break;
                                case "playing":
                                    _isChangedByController = true;
                                    viewModelVideoInfo.Status = VideoState.Playing;
                                    break;
                                case "buffering":
                                    _isChangedByController = true;
                                    viewModelVideoInfo.Status = VideoState.Playing;
                                    break;
                            }
                        }
                    }
                }
            }
        }
        private void HandleGetPlayingStateCallback(Event callback)
        {
            if (callback.EventArgs != null && callback.ContainsEventArg("CallbackId")
                && callback.ContainsEventArg("State") && callback.ContainsEventArg("NodeId"))
            {
                var callbackId = callback.GetEventArgValue("CallbackId");
                var state = callback.GetEventArgValue("State");
                var viewModelIdAsString = callback.GetEventArgValue("NodeId");

                if (!string.IsNullOrEmpty(viewModelIdAsString))
                {
                    var viewModelId = new Guid(viewModelIdAsString);

                    foreach (var viewModelVideoInfo in ViewModels.Values)
                    {
                        if (viewModelVideoInfo.Id == viewModelId)
                        {
                            if (state == "Playing" || state == "Buffering")
                            {
                                _isChangedByController = true;
                                viewModelVideoInfo.Status = VideoState.Playing;
                            }
                            else
                            {
                                _isChangedByController = true;
                                viewModelVideoInfo.Status = VideoState.Pause;
                            }
                        }
                        else
                        {
                            if (viewModelVideoInfo.HasVideo)
                            {
                                _isChangedByController = true;
                                viewModelVideoInfo.Status = VideoState.Pause;
                            }
                        }
                    }
                }
            }
        }
 private void HandleSeekEvent(Event receivedEvent)
 {
     if (receivedEvent.EventArgs != null && receivedEvent.ContainsEventArg("NewPosition"))
     {
         if (ViewManager != null && ViewManager.CurrentView != null && ViewManager.CurrentView.NodeRenderers != null)
         {
             TimeSpan newPosition = TimeSpan.MinValue;
             if (TimeSpan.TryParse(receivedEvent.GetEventArgValue("NewPosition"), out newPosition))
             {
                 foreach (NodeRenderer nodeRenderer in ViewManager.CurrentView.NodeRenderers.Values)
                 {
                     if (nodeRenderer.ResetMediaIcon(newPosition))
                     {
                         break;
                     }
                 }
             }
         }
     }
 }
        private void HandleGetPlayingStateCallback(Event callback) 
        {
            if (callback.EventArgs != null && callback.ContainsEventArg("CallbackId")
                && callback.ContainsEventArg("State") && callback.ContainsEventArg("NodeId"))
            {
                string callbackId = callback.GetEventArgValue("CallbackId");
                string state = callback.GetEventArgValue("State");
                string currentlyPlayingNodeId = callback.GetEventArgValue("NodeId");

                if (ViewManager != null && ViewManager.CurrentView != null)
                {
                    if (callbackId == Navigator.FocalNodeId.ToString()) //the request was made for this map refresh
                    {
                        if (state == "Playing" || state == "Buffering")
                        {
                            foreach (NodeRenderer nodeRenderer in ViewManager.CurrentView.NodeRenderers.Values)
                            {
                                if (nodeRenderer.Node.Id.ToString() == currentlyPlayingNodeId)
                                {
                                    nodeRenderer.SetIsPlaying(true);
                                    nodeRenderer.ResetMediaIcon(true);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        private void MediaPlayer_MarkerReached(object sender, TimelineMarkerRoutedEventArgs e)
        {
            if (e.Marker.Type == "EndTimeCode")
            {
                MediaPlayer.Pause();
                SeekToMediaPosition(CurrentNode.StartTimeCodeProvided
                    ? CurrentNode.StartTime
                    : TimeSpan.Parse("00:00:00"));
                MediaPlayer_CurrentStateChanged(sender, new RoutedEventArgs());
                MainUI.PlayControl.StopState();
            }

            var markerEvent = new Event
            {
                Name = "TimelineMarkerEvent",
                EventArgs = new List<EventArg>
                {
                    {new EventArg() { Name="Text", Value=e.Marker.Text}},
                    {new EventArg() { Name="Time", Value=e.Marker.Time.TotalSeconds.ToString(CultureInfo.InvariantCulture)}},
                    {new EventArg() { Name="Type", Value=e.Marker.Type}}
                }
            };
            MainUI.Controller.SendEvent(markerEvent);
            //CurrentNode.PlayingTime = new TimeSpan();
        }
 private void MediaPlayer_CurrentStateChanged(object sender, RoutedEventArgs e)
 {
     if (CurrentNode != null && CurrentNode.CurrentState != null && CurrentNode.CurrentState.GetState() != MediaPlayer.CurrentState)
     {
         var stateChangeEvent = new Event
         {
             Name = "CurrentStateChanged",
             EventArgs = new List<EventArg>()
         };
         if (CurrentNode != null)
         {
             stateChangeEvent.EventArgs.Add(new EventArg() { Name = "NodeId", Value = CurrentNode.NodeId.ToString() });
         }
         if (CurrentNode != null && CurrentNode.CurrentState != null)
         {
             CurrentNode.CurrentState.SetState(MediaPlayer.CurrentState);
         }
         switch (MediaPlayer.CurrentState)
         {
             case MediaElementState.Playing:
                 if (MediaPlayer.Markers.Count == 0 && CurrentNode.EndTimeCodeProvided)
                 {
                     MediaPlayer.Markers.Add(new TimelineMarker
                     {
                         Time = CurrentNode.EndTime,
                         Text = "EndTimeCode",
                         Type = "EndTimeCode"
                     });
                 }
                 MainUI.LoadingPanel.Close();
                 MainUI.SliderControl.StartTimer();
                 MainUI.PlayControl.PlayState();
                 stateChangeEvent.EventArgs.Add(new EventArg() { Name = "State", Value = "Playing" });
                 break;
             case MediaElementState.Buffering:
                 MainUI.LoadingPanel.Show();
                 MainUI.PlayControl.PlayState();
                 stateChangeEvent.EventArgs.Add(new EventArg() { Name = "State", Value ="Buffering"});
                 break;
             case MediaElementState.Opening:
                 MainUI.LoadingPanel.Show();
                 MainUI.PlayControl.PlayState();
                 stateChangeEvent.EventArgs.Add(new EventArg() { Name = "State", Value ="Playing"});
                 break;
             case MediaElementState.Closed:
                 MainUI.LoadingPanel.Close();
                 MainUI.PlayControl.StopState();
                 stateChangeEvent.EventArgs.Add(new EventArg() { Name = "State", Value ="Idle"});
                 break;
             case MediaElementState.Stopped:
                 MainUI.LoadingPanel.Close();
                 MainUI.PlayControl.StopState();
                 stateChangeEvent.EventArgs.Add(new EventArg() { Name = "State", Value ="Idle"});
                 break;
             case MediaElementState.Paused:
                 MainUI.LoadingPanel.Close();
                 MainUI.PlayControl.StopState();
                 stateChangeEvent.EventArgs.Add(new EventArg() { Name = "State", Value = "Idle"});
                 break;
             default:
                 MainUI.LoadingPanel.Close();
                 stateChangeEvent.EventArgs.Add(new EventArg() { Name = "State", Value = "Idle" });
                 MainUI.SliderControl.StopTimer();
                 MainUI.PlayControl.StopState();
                 break;
         }
         
         MainUI.Controller.SendEvent(stateChangeEvent);
     }
 }
 private void MediaPlayer_MediaEnded(object sender, RoutedEventArgs e)
 {
     var mediaEndedEvent = new Event { Name = "CurrentStateChanged", EventArgs = new List<EventArg>() };
     mediaEndedEvent.EventArgs.Add(new EventArg() { Name = "State", Value = "Idle" });
     if (CurrentNode != null)
     {
         mediaEndedEvent.EventArgs.Add(new EventArg() { Name = "NodeId", Value = CurrentNode.NodeId.ToString() });
     }
     MainUI.Controller.SendEvent(mediaEndedEvent);
     MainUI.PlayControl.StopState();
     SetMediaPlayToStart();
 }
 private void MediaPlayer_MediaFailed(object sender, ExceptionRoutedEventArgs e)
 {
     MainUI.LoadingPanel.Close();
     MainUI.ErrorPanel.Visibility = Visibility.Visible;
     MediaPlayer.Visibility = Visibility.Collapsed;
     MediaPlayer.Source = null;
     var mediaFailedEvent = new Event
     {
         Name = "MediaFailedEvent",
         EventArgs = new List<EventArg> { {new EventArg() { Name = "ErrorExplanation", Value = e.ErrorException.Message} } }
     };
     MainUI.Controller.SendEvent(mediaFailedEvent);
 }
        private void MediaPlayer_MediaOpened(object sender, RoutedEventArgs e)
        {
            MediaPlayer.Markers.Clear();
            MainUI.SliderControl.Maximum = MediaPlayer.NaturalDuration.TimeSpan.TotalMilliseconds;
            var mediaOpenedEvent = new Event
            {
                Name = "MediaOpened",
                EventArgs = new List<EventArg> { { new EventArg() { Name = "Source", Value = MediaPlayer.Source.ToString()} } }
            };
            MainUI.Controller.SendEvent(mediaOpenedEvent);
            if (CurrentNode != null && CurrentNode.StartTimeCodeProvided)
            {
                SeekToMediaPosition(CurrentNode.StartTime);
                if (MediaPlayer.Markers.Count == 0 && CurrentNode.EndTimeCodeProvided)
                {
                    MediaPlayer.Markers.Add(new TimelineMarker
                    {
                        Time = CurrentNode.EndTime,
                        Text = "EndTimeCode",
                        Type = "EndTimeCode"
                    });
                }
            }

            if(MediaPlayer.CurrentState == MediaElementState.Playing || MediaPlayer.CurrentState == MediaElementState.Paused)
                MainUI.LoadingPanel.Close();
        }
 private void VideoNodesControllerOnNodeChanged(object sender, NodeChangedEventArgs e)
 {
     var stateChangeEvent = new Event
     {
         Name = "CurrentStateChanged",
         EventArgs = new List<EventArg>()
     };
     stateChangeEvent.EventArgs.Add(new EventArg() { Name = "NodeId", Value = string.Format("{0}", e.Old) });
     stateChangeEvent.EventArgs.Add(new EventArg() { Name = "State", Value = "Idle" });
     MainUI.Controller.SendEvent(stateChangeEvent);
 }
        public void SeekToMediaPosition(TimeSpan position)
        {
            MediaPlayer.Position = position;
            //if (CurrentNode != null)
            //{
            //    CurrentNode.PlayingTime = position;
            //}
            if (MediaPlayer.Markers.Count > 0)
            {
                var currentEndTimeMarker = MediaPlayer.Markers[0].Time; //get the end time marker
                if (position > currentEndTimeMarker) //have seeked beyond the marker
                {
                    MediaPlayer.Markers.Clear();
                    MainUI.SliderControl.HasSeekedBeyondEnd = true;
                }
            }
            else
            {
                MainUI.SliderControl.HasSeekedBeyondEnd = false;
            }

            var seekEvent = new Event
            {
                Name = "Seek",
                EventArgs = new List<EventArg>() { { new EventArg() { Name = "NewPosition", Value = position.ToString()} } }
            };
            MainUI.Controller.SendEvent(seekEvent);
        }
Exemple #16
0
 private void HandleGetPlayingStateCallback(Event e)
 {
     if (e.EventArgs != null && e.ContainsEventArg("State") && e.ContainsEventArg("NodeId"))
     {
         if (NodeProxy.Id.ToString() == e.GetEventArgValue("NodeId"))
         {
             switch (e.GetEventArgValue("State"))
             {
                 case "Playing":
                     pauseVideoMenuItem.IsEnabled = true;
                     break;
                 case "Paused":
                     pauseVideoMenuItem.IsEnabled = false;
                     break;
                 default:
                     pauseVideoMenuItem.IsEnabled = false;
                     break;
             }
         }
     }
 }
Exemple #17
0
        private void HandleGetSourceAndPositionCallback(Event callback)
        {
            if (callback.EventArgs != null && callback.ContainsEventArg("CallbackId")
                && callback.ContainsEventArg("Position") && callback.ContainsEventArg("Source")
                && callback.ContainsEventArg("NodeId"))
            {
                string callbackId = callback.GetEventArgValue("CallbackId");
                string source = callback.GetEventArgValue("Source");
                source = HttpUtility.UrlDecode(source); 
                string viewModelIdAsString = callback.GetEventArgValue("NodeId");

                if (!string.IsNullOrEmpty(viewModelIdAsString) && !string.IsNullOrEmpty(source))
                {
                    var chain = new TransactionChain();
                    var viewModelId = new Guid(viewModelIdAsString);
                    var viewModelVideoInfo = ViewModels[viewModelId];

                    switch (callbackId)
                    {
                        case "StartPosition":
                            {
                                TimeSpan startPosition = TimeSpan.Parse(callback.GetEventArgValue("Position"));
                                // Just add a temporary end position so that the entry doesn't end up in a bad state.
                                ViewModel.IMetadata startPositionMetadata = viewModelVideoInfo.Context.Metadata["Video.StartPosition"];

                                if (startPositionMetadata != null)
                                {
                                    startPositionMetadata.SetValue(startPosition.ToString(), ref chain); 
                                    ((SuperGraph.ViewModel.Node)viewModelVideoInfo.Context).NodeProperties.UIMetadata["Video.StartPosition"] = startPosition.ToString();
                                }
                                else
                                {
                                    viewModelVideoInfo.Context.Metadata.Add("Video.StartPosition", startPosition.ToString(), ref chain);
                                    ((SuperGraph.ViewModel.Node)viewModelVideoInfo.Context).NodeProperties.UIMetadata.Add("Video.StartPosition", startPosition.ToString());
                                }

                                ViewModel.IMetadata endPositionMetadata = viewModelVideoInfo.Context.Metadata["Video.EndPosition"];

                                if (endPositionMetadata != null)
                                {
                                    endPositionMetadata.SetValue("", ref chain);
                                }
                                else
                                {
                                    viewModelVideoInfo.Context.Metadata.Add("Video.EndPosition", "", ref chain);
                                    ((SuperGraph.ViewModel.Node)viewModelVideoInfo.Context).NodeProperties.UIMetadata.Add("Video.EndPosition", "");
                                }

                                viewModelVideoInfo.HasVideo = true;
                                viewModelVideoInfo.StartPosition = startPosition;
                                viewModelVideoInfo.StopPosition = null;
                                break;
                            }
                        case "EndPosition":
                            {
                                TimeSpan endPosition = TimeSpan.Parse(callback.GetEventArgValue("Position"));

                                ViewModel.IMetadata endPositionMetadata = viewModelVideoInfo.Context.Metadata["Video.EndPosition"];

                                if (endPositionMetadata != null)
                                {
                                    endPositionMetadata.SetValue("", ref chain);
                                    ((SuperGraph.ViewModel.Node)viewModelVideoInfo.Context).NodeProperties.UIMetadata["Video.EndPosition"] = endPosition.ToString();
                                }
                                else
                                {
                                    viewModelVideoInfo.Context.Metadata.Add("Video.EndPosition", "", ref chain);
                                    ((SuperGraph.ViewModel.Node)viewModelVideoInfo.Context).NodeProperties.UIMetadata.Add("Video.EndPosition", endPosition.ToString());
                                }

                                viewModelVideoInfo.Context.Metadata.Add(null, null, "Video.EndPosition", endPosition.ToString(), ref chain);
                                viewModelVideoInfo.StopPosition = endPosition;
                                viewModelVideoInfo.HasVideo = true;
                                break;
                            }
                    }

                    ViewModel.IMetadata videoSourceMetadata = viewModelVideoInfo.Context.Metadata["Video.Source"];

                    if (videoSourceMetadata != null)
                    {
                        videoSourceMetadata.SetValue(source, ref chain);
                        ((SuperGraph.ViewModel.Node) viewModelVideoInfo.Context).NodeProperties.UIMetadata[
                            "Video.Source"] = source;
                    }
                    else
                    {
                        viewModelVideoInfo.Context.Metadata.Add(null, null, "Video.Source", source, ref chain);
                        ((SuperGraph.ViewModel.Node)viewModelVideoInfo.Context).NodeProperties.UIMetadata.Add("Video.Source", source);
                    }
                    viewModelVideoInfo.VideoSource = source;
                    viewModelVideoInfo.Context.Proxy.MapManager.ExecuteTransaction(chain);
                }
            }
        }
 private void HandledCurrentStateChanged(Event receivedEvent)
 {
     if (receivedEvent.EventArgs != null && receivedEvent.ContainsEventArg("State"))
     {
         string state = receivedEvent.GetEventArgValue("State");
         Guid nodeId = Guid.Empty;
         if (receivedEvent.ContainsEventArg("NodeId"))
         {
             Guid.TryParse(receivedEvent.GetEventArgValue("NodeId"), out nodeId);
         }
         if (!string.IsNullOrEmpty(state) && state.ToLower() == "idle")
         {
             ResetNodeRendererMediaIcon(nodeId, false);
         }
         else if (!string.IsNullOrEmpty(state) && state.ToLower() == "playing")
         {
             ResetNodeRendererMediaIcon(nodeId, true);
         }
         else if (!string.IsNullOrEmpty(state) && state.ToLower() == "buffering")
         {
             ResetNodeRendererMediaIcon(nodeId, true);
         }
     }
 }
Exemple #19
0
 private void HandlePlayerDisposedEvent(Event disposedEvent)
 {
     _cachedCommand = null;
     _playerInitialised = false;
     if (disposedEvent.EventArgs != null && disposedEvent.ContainsEventArg("NodeId"))
     {
         string viewModelIdAsString = disposedEvent.GetEventArgValue("NodeId");
         var viewModelId = new Guid(viewModelIdAsString);
         if (ViewModels.ContainsKey(viewModelId))
         {
             VideoInfo viewModelVideoInfo = ViewModels[viewModelId];
             _isChangedByController = true;
             viewModelVideoInfo.Status = VideoState.Pause;
         }
     }
 }
 private void HandleReplayingLastNodeEvent(Event receivedEvent)
 {
     if (ViewManager != null && ViewManager.CurrentView != null && ViewManager.CurrentView.NodeRenderers != null
         && receivedEvent.EventArgs != null && receivedEvent.ContainsEventArg("NodeId"))
     {
         Guid nodeId = Guid.Empty;
         if (Guid.TryParse(receivedEvent.GetEventArgValue("NodeId"), out nodeId)) 
         {
             NodeRenderer playingNode = ViewManager.CurrentView.NodeRenderers[nodeId];
             {
                 playingNode.SetIsPlaying(true);
                 playingNode.ResetMediaIcon(true);
             }
         }
     }
 }
 public void Send(Event e)
 {
     Utilities.SendMessage(_sender, e);
 }