Esempio n. 1
0
        public override Playlist parse()
        {
            validateAvailable();

            ParseState      state           = new ParseState(mEncoding);
            TrackLineParser trackLineParser = new TrackLineParser();

            try
            {
                state.setMedia();

                while (mScanner.hasNext())
                {
                    String line = mScanner.next();
                    validateLine(line);

                    if (line.Length == 0 || isComment(line))
                    {
                        continue;
                    }
                    else
                    {
                        trackLineParser.parse(line, state);
                    }
                }

                Playlist playlist = new Playlist.Builder()
                                    .withMediaPlaylist(new MediaPlaylist.Builder()
                                                       .withTracks(state.getMedia().tracks)
                                                       .build())
                                    .build();

                PlaylistValidation validation = PlaylistValidation.from(playlist);

                if (validation.isValid())
                {
                    return(playlist);
                }
                else
                {
                    throw new PlaylistException(mScanner.getInput(), validation.getErrors());
                }
            }
            catch (ParseException exception)
            {
                exception.setInput(mScanner.getInput());
                throw exception;
            }
        }
Esempio n. 2
0
        public Playlist buildPlaylist()
        {
            Playlist.Builder playlistBuilder = new Playlist.Builder();

            if (isMaster())
            {
                playlistBuilder.withMasterPlaylist(buildInnerPlaylist(getMaster()));
            }
            else if (isMedia())
            {
                playlistBuilder
                .withMediaPlaylist(buildInnerPlaylist(getMedia()))
                .withExtended(mIsExtended);
            }
            else
            {
                throw new ParseException(ParseExceptionType.UNKNOWN_PLAYLIST_TYPE);
            }

            return(playlistBuilder
                   .withCompatibilityVersion(mCompatibilityVersion == NONE ? Playlist.MIN_COMPATIBILITY_VERSION : mCompatibilityVersion)
                   .build());
        }