public void SetDescriptionImage(AlternateContent altContent, string fullPath) { Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection(); TreeNode node = selection.Item2 ?? selection.Item1; if (node == null) { return; } var altProp = node.GetAlternateContentProperty(); if (altProp == null) { return; } if (altProp.AlternateContents.IndexOf(altContent) < 0) { return; } if (string.IsNullOrEmpty(fullPath)) { if (altContent.Image != null) { AlternateContentRemoveManagedMediaCommand cmd1 = node.Presentation.CommandFactory.CreateAlternateContentRemoveManagedMediaCommand(node, altContent, altContent.Image); node.Presentation.UndoRedoManager.Execute(cmd1); } } else if (File.Exists(fullPath)) { string extension = Path.GetExtension(fullPath); if (string.IsNullOrEmpty(extension)) { return; } ManagedImageMedia img1 = node.Presentation.MediaFactory.CreateManagedImageMedia(); ImageMediaData imgData1 = node.Presentation.MediaDataFactory.CreateImageMediaData(extension); if (imgData1 == null) { return; } imgData1.InitializeImage(fullPath, Path.GetFileName(fullPath)); img1.ImageMediaData = imgData1; AlternateContentSetManagedMediaCommand cmd22 = node.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(node, altContent, img1); node.Presentation.UndoRedoManager.Execute(cmd22); } RaisePropertyChanged(() => Descriptions); }
public void SetDescriptionAudio(AlternateContent altContent, ManagedAudioMedia manMedia, TreeNode node) { if (manMedia == null || manMedia.HasActualAudioMediaData && !manMedia.Duration.IsGreaterThan(Time.Zero)) { if (altContent.Audio != null) { AlternateContentRemoveManagedMediaCommand cmd1 = node.Presentation.CommandFactory.CreateAlternateContentRemoveManagedMediaCommand(node, altContent, altContent.Audio); node.Presentation.UndoRedoManager.Execute(cmd1); } } else { ManagedAudioMedia audio1 = node.Presentation.MediaFactory.CreateManagedAudioMedia(); AudioMediaData audioData1 = node.Presentation.MediaDataFactory.CreateAudioMediaData(); audio1.AudioMediaData = audioData1; // WARNING: WavAudioMediaData implementation differs from AudioMediaData: // the latter is naive and performs a stream binary copy, the latter is optimized and re-uses existing WavClips. // WARNING 2: The audio data from the given parameter gets emptied ! //audio1.AudioMediaData.MergeWith(manMedia.AudioMediaData); if (!audio1.AudioMediaData.PCMFormat.Data.IsCompatibleWith(manMedia.AudioMediaData.PCMFormat.Data)) { throw new InvalidDataFormatException( "Can not merge description audio with a AudioMediaData with incompatible audio data"); } Stream stream = manMedia.AudioMediaData.OpenPcmInputStream(); try { audio1.AudioMediaData.AppendPcmData(stream, null); //manMedia.AudioMediaData.AudioDuration } finally { stream.Close(); } AlternateContentSetManagedMediaCommand cmd22 = node.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(node, altContent, audio1); node.Presentation.UndoRedoManager.Execute(cmd22); } RaisePropertyChanged(() => Descriptions); }
public void SetDescriptionText(AlternateContent altContent, string txt) { Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection(); TreeNode node = selection.Item2 ?? selection.Item1; if (node == null) { return; } var altProp = node.GetAlternateContentProperty(); if (altProp == null) { return; } if (altProp.AlternateContents.IndexOf(altContent) < 0) { return; } if (string.IsNullOrEmpty(txt)) { if (altContent.Text != null) { AlternateContentRemoveManagedMediaCommand cmd1 = node.Presentation.CommandFactory.CreateAlternateContentRemoveManagedMediaCommand(node, altContent, altContent.Text); node.Presentation.UndoRedoManager.Execute(cmd1); } } else { TextMedia txt2 = node.Presentation.MediaFactory.CreateTextMedia(); txt2.Text = txt; AlternateContentSetManagedMediaCommand cmd22 = node.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(node, altContent, txt2); node.Presentation.UndoRedoManager.Execute(cmd22); } RaisePropertyChanged(() => Descriptions); }