Parser for the .srt subtitles files A .srt file looks like: 1 00:00:10,500 --> 00:00:13,000 Elephant's Dream 2 00:00:15,000 --> 00:00:18,000 At the left we can see...[12]
상속: ISubtitlesParser
예제 #1
0
    private void LoadSubtitles(VideoClip videoClip)
    {
        var parser = new SubtitlesParser.Classes.Parsers.SrtParser();

        // Text Asset does not support the .srt file extensions. That is why I use .txt instead.
        // However, when loading a TextAsset, file extension shall be omitted when referencing to its file name.
        TextAsset subtitleAsset = Resources.Load <TextAsset>(videoClip.name);

        // Is subtitles are available for the clip, parse them.
        if (subtitleAsset != null)
        {
            byte[]       byteArray = Encoding.UTF8.GetBytes(subtitleAsset.text);
            MemoryStream stream    = new MemoryStream(byteArray);
            subtitleItems = parser.ParseStream(stream, Encoding.UTF8);
        }
    }
    public void VideoPlayPause()
    {
        // Pause if playing, Resume if paused, Play if stopped
        if (video.playerState == PS4VideoPlayer.VidState.PLAY)
        {
            video.Pause();
        }
        else if (video.playerState == PS4VideoPlayer.VidState.PAUSE)
        {
            video.Resume();
            //playPauseIcon.sprite = pauseIcon;
        }
        else
        {
            try
            {
                video.Play(moviePath, isLooping);

                StopAllCoroutines();
                StartCoroutine(CheckDimensions(moviePath));

                // cargar subtitulos si existen y si se llaman igual al video
                string caminoSub = moviePath.Replace(Path.GetExtension(moviePath), "");
                if (File.Exists(caminoSub + ".srt"))
                {
                    SubtitlesParser.Classes.Parsers.SrtParser parser = new SubtitlesParser.Classes.Parsers.SrtParser();

                    Subtitulos.text = "";
                    linea           = 0;
                    itemsubs        = parser.ParseStream(caminoSub + ".srt");
                }
                else if (File.Exists(caminoSub + ".ssa"))
                {
                    SubtitlesParser.Classes.Parsers.SsaParser parser = new SubtitlesParser.Classes.Parsers.SsaParser();

                    Subtitulos.text = "";
                    linea           = 0;
                    itemsubs        = parser.ParseStream(caminoSub + ".ssa");
                }
                else if (File.Exists(caminoSub + ".ass"))
                {
                    SubtitlesParser.Classes.Parsers.SsaParser parser = new SubtitlesParser.Classes.Parsers.SsaParser();

                    Subtitulos.text = "";
                    linea           = 0;
                    itemsubs        = parser.ParseStream(caminoSub + ".ass");
                }
                else
                {
                    linea    = 0;
                    itemsubs = null;
                }
            }
            catch (Exception ex)
            {
                linea           = 0;
                itemsubs        = null;
                Subtitulos.text = "Error: " + ex.Message;
            }
        }

        // Calling Play ignores the current mute settings. This reapplies them
        video.SetVolume(Volumen);
    }