/// <summary> /// Button to deactivate all slots in the current track. /// </summary> /// <param name="sender">Button object for event as Button</param> /// <param name="e">RoutedEventArgs</param> private void DeactivateAllSlots(object sender, RoutedEventArgs e) { var parentStackPanel = (sender as Button).Parent; var parentTrackStackPanel = (parentStackPanel as StackPanel).Parent; var parentTrackGrid = (parentTrackStackPanel as StackPanel).Parent; var parentSequencerTrackUI = (parentTrackGrid as Grid).Parent; var trackName = (parentSequencerTrackUI as SequencerTrackUI).Name; // Extract the track ID for the button that triggered the loading event. trackName = trackName.Substring(14); int selectedTrack = 0; selectedTrack = int.Parse(trackName); // Iterate through the UI elements and deactivate the checkboxes. for (int i = 0; i < 8; i++) { // Get the respective item, update the active state and store it back again. SequencerSlot slotItemForUpdate = this.globalSequencerDataInstance.getSlotAtPosition(selectedTrack, i); slotItemForUpdate.active = true; // Get the current slot activity button. Button slotActivateButtonElement = (Button)this.FindName("Slot" + i.ToString() + "Active"); this.ActivateSlot(slotActivateButtonElement, null); } }
/// <summary> /// A sequencer slot has been clicked to load a new video into the /// respective slot. /// </summary> /// <param name="sender">The button for the respective slot as Button</param> /// <param name="e">RoutedEventArgs</param> private async void LoadNewVideoForSlot(object sender, RoutedEventArgs e) { // Retrieve slot and track names. var parentSlotStackPanel = (sender as Button).Parent; var slotName = (parentSlotStackPanel as StackPanel).Name; var parentTrackStackPanel = (parentSlotStackPanel as StackPanel).Parent; var parentTrackGrid = (parentTrackStackPanel as StackPanel).Parent; var parentSequencerTrackUI = (parentTrackGrid as Grid).Parent; var trackName = (parentSequencerTrackUI as SequencerTrackUI).Name; // Create the file picker. FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary; // Define that only video files are interesting. openPicker.FileTypeFilter.Add(".mp4"); openPicker.FileTypeFilter.Add(".mkv"); openPicker.FileTypeFilter.Add(".avi"); openPicker.FileTypeFilter.Add(".mov"); // Open the file picker and wait for the result. StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { // Extract the track ID for the button that triggered the loading event. trackName = trackName.Substring(14); int selectedTrack = 0; selectedTrack = int.Parse(trackName); // Extract the slot ID for the button that triggered the loading event. slotName = slotName.Substring(4); int selectedSlot = 0; selectedSlot = int.Parse(slotName); // Create a new slot item to fill. SequencerSlot newSlotItem = new SequencerSlot(); // Fill the slot items with the video source and other info. newSlotItem.active = false; newSlotItem.videoFile = file; newSlotItem.videoMediaSource = MediaSource.CreateFromStorageFile(file); newSlotItem.thumbnail = await file.GetThumbnailAsync(ThumbnailMode.SingleItem); // Store new slot information in global squencer data. this.globalSequencerDataInstance.setSlotAtPosition(selectedTrack, selectedSlot, newSlotItem); // Load the thumbnail image and show it in the UI on the respective button. BitmapImage image = new BitmapImage(); ImageBrush imagebrush = new ImageBrush(); image.SetSource(newSlotItem.thumbnail); imagebrush.ImageSource = image; (sender as Button).Background = imagebrush; } }
/// <summary> /// Button to clear all slots in the current track. /// </summary> /// <param name="sender">Button object for event as Button</param> /// <param name="e">RoutedEventArgs</param> private void ClearAllSlots(object sender, RoutedEventArgs e) { var parentStackPanel = (sender as Button).Parent; var parentTrackStackPanel = (parentStackPanel as StackPanel).Parent; var parentTrackGrid = (parentTrackStackPanel as StackPanel).Parent; var parentSequencerTrackUI = (parentTrackGrid as Grid).Parent; var trackName = (parentSequencerTrackUI as SequencerTrackUI).Name; // Extract the track ID for the button that triggered the loading event. trackName = trackName.Substring(14); int selectedTrack = 0; selectedTrack = int.Parse(trackName); // Iterate through the UI elements and deactivate the checkboxes. for (int i = 0; i < 8; i++) { // Get the respective item, update the active state and store it back again. SequencerSlot slotItemForUpdate = this.globalSequencerDataInstance.getSlotAtPosition(selectedTrack, i); slotItemForUpdate.active = true; // Get the current slot activity button. Button slotActivateButtonElement = (Button)this.FindName("Slot" + i.ToString() + "Active"); this.ActivateSlot(slotActivateButtonElement, null); // Create a new slot item to fill. SequencerSlot newSlotItem = new SequencerSlot(); // Fill the slot items with empty data. newSlotItem.active = false; newSlotItem.videoFile = null; newSlotItem.videoMediaSource = null; newSlotItem.thumbnail = null; // Store new slot information in global squencer data. this.globalSequencerDataInstance.setSlotAtPosition(selectedTrack, i, newSlotItem); // Clear the slot button. Button videoSlotToClear = (Button)this.FindName("Slot" + i.ToString() + "Button"); videoSlotToClear.Background = this.themeButtonColor; } }
/// <summary> /// A slot activity indicator has been clicked to either activate or /// deactivate the slot. /// </summary> /// <param name="sender">The activation element for the respective slot as CheckBox</param> /// <param name="e">RoutedEventArgs</param> private void ActivateSlot(object sender, RoutedEventArgs e) { // Retrieve slot and track names. var parentSlotStackPanel = (sender as Button).Parent; var slotName = (parentSlotStackPanel as StackPanel).Name; var parentTrackStackPanel = (parentSlotStackPanel as StackPanel).Parent; var parentTrackGrid = (parentTrackStackPanel as StackPanel).Parent; var parentSequencerTrackUI = (parentTrackGrid as Grid).Parent; var trackName = (parentSequencerTrackUI as SequencerTrackUI).Name; // Extract the track ID for the button that triggered the loading event. trackName = trackName.Substring(14); int selectedTrack = 0; selectedTrack = int.Parse(trackName); // Extract the slot ID for the button that triggered the loading event. slotName = slotName.Substring(4); int selectedSlot = 0; selectedSlot = int.Parse(slotName); // Get the respective item, update the active state and store it back again. SequencerSlot slotItemForUpdate = this.globalSequencerDataInstance.getSlotAtPosition(selectedTrack, selectedSlot); slotItemForUpdate.active = !slotItemForUpdate.active; this.globalSequencerDataInstance.setSlotAtPosition(selectedTrack, selectedSlot, slotItemForUpdate); if (slotItemForUpdate.active) { (sender as Button).Background = new SolidColorBrush(Color.FromArgb(255, 0, 120, 215)); } else { (sender as Button).Background = this.themeButtonColor; } }
/// <summary> /// This is triggered if the sequencer progressed. /// </summary> /// <param name="currentSequencerPosition">The updated sequencer position as int</param> /// <param name="e">PropertyChangedEventArgs</param> private async void SequencerTrigger(object currentSequencerPosition, PropertyChangedEventArgs e) { // Get the correct thread for the media player UI. await this.globalEventHandlerInstance.playerDispatcher.RunAsync( CoreDispatcherPriority.Normal, () => { // Iterate through all 4 media players. for (int i = 0; i < 4; i++) { // Get the media player element for the current track. MediaPlayerElement currentMediaElement = (MediaPlayerElement)this.FindName("mediaPlayerElementTrack" + i.ToString()); // Get the video item for the current sequencer position. SequencerSlot currentSlotItem = globalSequencerDataInstance.getSlotAtPosition(i, (int)currentSequencerPosition); // Check if the current step has a video in it. if ((currentSlotItem.videoMediaSource != null) && (currentSlotItem.active)) { // CHeck if the video in the next step is another video than the one currently playing. if ((this.currentlyActiveVideoFile[i] == null) || (this.currentlyActiveVideoFile[i] != currentSlotItem.videoFile.Name)) { // If so, then bind the video source to the video player and start playing the new source. currentMediaElement.MediaPlayer.Source = currentSlotItem.videoMediaSource; currentMediaElement.MediaPlayer.Play(); this.currentlyActiveVideoFile[i] = currentSlotItem.videoFile.Name; } else { // If it's the same video, just reset the video position and start playing. currentMediaElement.MediaPlayer.PlaybackSession.Position = TimeSpan.Zero; currentMediaElement.MediaPlayer.Play(); } } } }); }
/// <summary> /// Stores a new video item into a given sequencer position. /// </summary> /// <param name="sequencerPosition">The position on the sequencer board to associate the video with</param> /// <param name="newVideoItem">The video item to store</param> public void setSlotAtPosition(int sequencerTrack, int sequencerPosition, SequencerSlot newVideoItem) { tracks[sequencerTrack].slots[sequencerPosition] = newVideoItem; }