コード例 #1
0
ファイル: PlayerState.cs プロジェクト: jmbe/buttercup-swedish
        /// <summary>
        /// Asynchronously loads the audio for the current phrase.
        /// </summary>
        /// <param name="smilReferenceID"></param>
        private void GetPhraseAudio(PhraseConstructionKit phraseConstruction)
        {
            //Determine whether current phrase has changed (to determine whether the 'new' phrase
            // should be started or resumed).
            string currentSmilReference = String.Format("{0}#{1}", phraseConstruction.SmilPath,
                    phraseConstruction.SmilReferenceID);
            _canResumePhrase = _canResumePhrase && ( currentSmilReference == _activeSmilReference );
            _activeSmilReference = currentSmilReference;

            //Extract SMIL object to get media file path, start & stop times.
            XElement audioElement = _activeSmilDocument.GetAudioElementBySmilID(phraseConstruction.SmilReferenceID);
            phraseConstruction.AudioElement = audioElement;
            if(audioElement != null)
            {
                XAttribute audioSrc = audioElement.Attribute("src");
                if(audioSrc != null)
                {
                    string audioFilePath = audioSrc.Value;
                    audioFilePath = _mainState.BookFileSystem.CombinePath
                            (_mainState.CurrentBook.FolderPath.FullName, audioFilePath);

                    Logger.Log("OpenAsync Audio File {0}", audioFilePath);

                    //Need to coerce the expected file next to be received.
                    _currentRequestedFileUri = audioFilePath;
                    phraseConstruction.AudioFilePath = audioFilePath;

                    IFile currentFile = _mainState.BookFileSystem.GetFile(audioFilePath);
                    currentFile.OpenAsyncComplete += GetPhraseAudioComplete;
                    currentFile.OpenAsync(phraseConstruction);
                }
            }
            else
            {
                if(PresentPhrase != null)
                {
                    PresentPhrase(phraseConstruction.ConstructedPhrase, _canResumePhrase);
                }
            }
        }
コード例 #2
0
ファイル: PlayerState.cs プロジェクト: jmbe/buttercup-swedish
        public void GetCurrentPhraseAsync(PlayerMode previousState)
        {
            _currentPhraseConstruction = new PhraseConstructionKit();
            Phrase currentPhrase = _currentPhraseConstruction.ConstructedPhrase;
            currentPhrase.Text = GetSpeakableText();
            currentPhrase.ElementID = Navigator.CurrentElementID;

            Book currentBook = _mainState.CurrentBook;
            string bookPath = currentBook.FolderPath.FullName;

            //Get SMIL path from book XML
            string smilPath;
            string smilReferenceID;

            string currentSmilReference = GetCurrentSmilReference();

            _canResumePhrase = previousState == PlayerMode.Paused;

            //We've been given an element with no SMIL Reference, aka Unspeakable
            //Since the navigation methods all only navigate speakable elements, this
            //only results from clicking on an element on the surface
            if(currentSmilReference == null)
            {
                XAttribute hasAltText = Navigator.CurrentElement.Attribute("alt");
                if(hasAltText != null)
                {
                    currentPhrase.Text = "Image. " + hasAltText.Value;
                }
                else
                {
                    currentPhrase.Text = "......"; //Could be anything, but each character represents a fixed length of silence
                    currentPhrase.Silent = true;
                }

                if(PresentPhrase != null)
                {
                    //Cannot resume - just speak.
                    PresentPhrase(currentPhrase, false);
                }

                return;
            }

            DeconstructSmilReference(currentSmilReference, out smilPath, out smilReferenceID);
            smilPath = _mainState.BookFileSystem.CombinePath(bookPath, smilPath);
            _currentPhraseConstruction.SmilPath = smilPath;
            _currentPhraseConstruction.SmilReferenceID = smilReferenceID;

            //Avoid repeat loading of previous SMIL document
            SmilDocument currentSmilDocument = _activeSmilDocument;
            if(currentSmilDocument == null || currentSmilDocument.SmilPath != smilPath)
            {
                //Need to coerce the expected file next to be received.
                _currentRequestedFileUri = smilPath;

                //Get corresponding SMIL file from file system
                IFile smilFile = _mainState.BookFileSystem.GetFile(smilPath);

                //Exception thrown if file doesn't exist.
                //Stream smilStream = smilFile.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
                smilFile.OpenAsyncComplete += GetSmilFileComplete;
                smilFile.OpenAsync(_currentPhraseConstruction);
            }
            else
            {
                GetPhraseAudio(_currentPhraseConstruction);
            }
        }