private urakawa.media.ExternalAudioMedia GetExternalAudioMedia(urakawa.core.TreeNode node)
        {
            List <urakawa.property.channel.Channel> channelsList = m_Presentation.ChannelsManager.GetChannelsByName(PUBLISH_AUDIO_CHANNEL_NAME);

            if (channelsList == null || channelsList.Count == 0)
            {
                return(null);
            }

            if (channelsList == null || channelsList.Count > 1)
            {
                throw new System.Exception("more than one publish channel cannot exist");
            }

            Channel publishChannel = channelsList[0];

            urakawa.property.channel.ChannelsProperty mediaProperty = node.GetProperty <ChannelsProperty>();

            if (mediaProperty == null)
            {
                return(null);
            }

            return((ExternalAudioMedia)mediaProperty.GetMedia(publishChannel));
        }
        public void Copy_ValueEqualsAfter()
        {
            urakawa.property.xml.XmlProperty newXmlProp = mPresentation.PropertyFactory.CreateXmlProperty();
            newXmlProp.SetQName("p", "");
            mRootNode.AddProperty(newXmlProp);
            mRootNode.AddProperty(mPresentation.PropertyFactory.CreateChannelsProperty());
            TreeNode mRootCopy = mRootNode.Copy(true);
            bool     equal     = mRootNode.ValueEquals(mRootCopy);

            Assert.IsTrue(equal, "The copy is not the same as the original");
            Assert.AreNotSame(mRootNode, mRootCopy, "The copy is just a reference of the original itself");
            foreach (Type propType in mRootCopy.UsedPropertyTypes)
            {
                Assert.AreNotEqual(
                    mRootNode.GetProperty(propType), mRootCopy.GetProperty(propType),
                    "Property of copy is just a reference to the property of the original");
            }
            for (int i = 0; i < mRootCopy.Children.Count; i++)
            {
                Assert.AreNotEqual(
                    mRootNode.Children.Get(i), mRootCopy.Children.Get(i),
                    "Child of copy is just a reference of the child of the original");
            }
        }
示例#3
0
        private void parseSmil(string fullSmilPath)
        {
            Presentation presentation = m_Project.GetPresentation(0);

            string dirPath = Path.GetDirectoryName(m_Book_FilePath);

            XmlDocument smilXmlDoc = readXmlDocument(fullSmilPath);

            XmlNodeList listOfAudioNodes = smilXmlDoc.GetElementsByTagName("audio");

            if (listOfAudioNodes != null)
            {
                foreach (XmlNode audioNode in listOfAudioNodes)
                {
                    XmlAttributeCollection attributeCol = audioNode.Attributes;

                    if (attributeCol != null)
                    {
                        XmlNode attrAudioSrc = attributeCol.GetNamedItem("src");
                        if (attrAudioSrc != null && !String.IsNullOrEmpty(attrAudioSrc.Value))
                        {
                            XmlNode parent = audioNode.ParentNode;
                            if (parent != null && parent.Name == "a")
                            {
                                parent = parent.ParentNode;
                            }

                            if (parent != null)
                            {
                                XmlNodeList listOfAudioPeers = parent.ChildNodes;
                                foreach (XmlNode peerNode in listOfAudioPeers)
                                {
                                    if (peerNode.NodeType == XmlNodeType.Element && peerNode.Name == "text")
                                    {
                                        XmlAttributeCollection peerAttrs = peerNode.Attributes;

                                        if (peerAttrs != null)
                                        {
                                            XmlNode attrTextSrc = peerAttrs.GetNamedItem("src");
                                            if (attrTextSrc != null && !String.IsNullOrEmpty(attrTextSrc.Value))
                                            {
                                                int index = attrTextSrc.Value.LastIndexOf('#');
                                                if (index < (attrTextSrc.Value.Length - 1))
                                                {
                                                    string        dtbookFragmentId = attrTextSrc.Value.Substring(index + 1);
                                                    core.TreeNode tNode            = getTreeNodeWithXmlElementId(dtbookFragmentId);
                                                    if (tNode != null)
                                                    {
                                                        AbstractAudioMedia existingAudioMedia = tNode.GetAudioMedia();
                                                        if (existingAudioMedia != null)
                                                        {
                                                            //Ignore.
                                                            //System.Diagnostics.Debug.Fail("TreeNode already has media ??");
                                                        }

                                                        XmlNode attrClipBegin = attributeCol.GetNamedItem("clipBegin");
                                                        XmlNode attrClipEnd   = attributeCol.GetNamedItem("clipEnd");

                                                        Media media = null;
                                                        if (attrAudioSrc.Value.EndsWith("wav"))
                                                        {
                                                            string fullWavPath = Path.Combine(dirPath,
                                                                                              attrAudioSrc.Value);

                                                            PCMDataInfo pcmInfo   = null;
                                                            Stream      wavStream = null;
                                                            try
                                                            {
                                                                wavStream = File.Open(fullWavPath, FileMode.Open,
                                                                                      FileAccess.Read, FileShare.Read);
                                                                pcmInfo = PCMDataInfo.ParseRiffWaveHeader(wavStream);
                                                                presentation.MediaDataManager.DefaultPCMFormat = pcmInfo.Copy();
                                                                TimeDelta duration = new TimeDelta(pcmInfo.Duration);

                                                                Time clipB = Time.Zero;
                                                                Time clipE = Time.MaxValue;

                                                                if (attrClipBegin != null &&
                                                                    !string.IsNullOrEmpty(attrClipBegin.Value))
                                                                {
                                                                    clipB = new Time(TimeSpan.Parse(attrClipBegin.Value));
                                                                }
                                                                if (attrClipEnd != null &&
                                                                    !string.IsNullOrEmpty(attrClipEnd.Value))
                                                                {
                                                                    clipE = new Time(TimeSpan.Parse(attrClipEnd.Value));
                                                                }
                                                                if (!clipB.IsEqualTo(Time.Zero) || !clipE.IsEqualTo(Time.MaxValue))
                                                                {
                                                                    duration = clipE.GetTimeDelta(clipB);
                                                                }
                                                                long byteOffset = 0;
                                                                if (!clipB.IsEqualTo(Time.Zero))
                                                                {
                                                                    byteOffset = pcmInfo.GetByteForTime(clipB);
                                                                }
                                                                if (byteOffset > 0)
                                                                {
                                                                    wavStream.Seek(byteOffset, SeekOrigin.Current);
                                                                }

                                                                presentation.MediaDataFactory.DefaultAudioMediaDataType =
                                                                    typeof(WavAudioMediaData);

                                                                WavAudioMediaData mediaData =
                                                                    (WavAudioMediaData)
                                                                    presentation.MediaDataFactory.CreateAudioMediaData();
                                                                mediaData.InsertAudioData(wavStream, Time.Zero, duration);

                                                                media = presentation.MediaFactory.CreateManagedAudioMedia();
                                                                ((ManagedAudioMedia)media).AudioMediaData = mediaData;
                                                            }
                                                            finally
                                                            {
                                                                if (wavStream != null)
                                                                {
                                                                    wavStream.Close();
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            media = presentation.MediaFactory.CreateExternalAudioMedia();
                                                            ((ExternalAudioMedia)media).Src = attrAudioSrc.Value;
                                                            if (attrClipBegin != null &&
                                                                !string.IsNullOrEmpty(attrClipBegin.Value))
                                                            {
                                                                ((ExternalAudioMedia)media).ClipBegin =
                                                                    new Time(TimeSpan.Parse(attrClipBegin.Value));
                                                            }
                                                            if (attrClipEnd != null &&
                                                                !string.IsNullOrEmpty(attrClipEnd.Value))
                                                            {
                                                                ((ExternalAudioMedia)media).ClipEnd =
                                                                    new Time(TimeSpan.Parse(attrClipEnd.Value));
                                                            }
                                                        }

                                                        ChannelsProperty chProp = tNode.GetProperty <ChannelsProperty>();
                                                        if (chProp == null)
                                                        {
                                                            chProp =
                                                                presentation.PropertyFactory.CreateChannelsProperty();
                                                            tNode.AddProperty(chProp);
                                                        }
                                                        chProp.SetMedia(m_audioChannel, media);
                                                        break; // scan peers to audio node
                                                    }
                                                    else
                                                    {
                                                        System.Diagnostics.Debug.Fail("XmlProperty with ID not found ??");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }