TeamNewPipe/NewPipe · error · IOException

Fragment element not found

Error message

Fragment element not found

What it means

WebMReader.parse() reads the EBML header, then calls untilElement(null, ID_SEGMENT) to find the top-level Segment element. If no Segment is found before the stream ends, it returns null and parse() throws IOException 'Fragment element not found'. Every valid WebM must contain a Segment; its absence means the file is truncated or not WebM.

Source

Thrown at app/src/main/java/org/schabi/newpipe/streams/WebMReader.java:72

    private WebMTrack[] tracks;
    private int selectedTrack;
    private boolean done;
    private boolean firstSegment;

    public WebMReader(final SharpStream source) {
        this.stream = new DataReader(source);
    }

    public void parse() throws IOException {
        Element elem = readElement(ID_EMBL);
        if (!readEbml(elem, 1, 2)) {
            throw new UnsupportedOperationException("Unsupported EBML data (WebM)");
        }
        ensure(elem);

        elem = untilElement(null, ID_SEGMENT);
        if (elem == null) {
            throw new IOException("Fragment element not found");
        }
        segment = readSegment(elem, 0, true);
        tracks = segment.tracks;
        selectedTrack = -1;
        done = false;
        firstSegment = true;
    }

    public WebMTrack[] getAvailableTracks() {
        return tracks;
    }

    public WebMTrack selectTrack(final int index) {
        selectedTrack = index;
        return tracks[index];
    }

    public Segment getNextSegment() throws IOException {

View on GitHub (pinned to 9e8be09156)

Solutions

  1. Re-download the full WebM file; the Segment payload is missing.
  2. Verify the source is actually a WebM/Matroska file and not just an EBML header.
  3. Check the download completed (full Content-Length) before parsing.
  4. Confirm range requests include the Segment region, not just the header.

Example fix

// no in-process fix for a missing Segment; validate the download
// before
new WebMReader(partialStream).parse(); // IOException: no Segment

// after — ensure the full file is present
if (downloadedLength < headerSize + minSegmentSize) {
    throw new IOException("download truncated before WebM segment");
}
new WebMReader(fullStream).parse();
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the file is long enough to contain an EBML header + Segment, and is WebM.
byte[] magic = new byte[4];
source.read(magic);
if ((magic[0]&0xFF)!=0x1A||(magic[1]&0xFF)!=0x45||(magic[2]&0xFF)!=0xDF||(magic[3]&0xFF)!=0xA3) {
    throw new IOException("not a WebM/Matroska file (bad EBML magic)");
}

Type guard

public static boolean hasEbmlMagic(byte[] head) {
    return head != null && head.length >= 4
        && (head[0]&0xFF)==0x1A && (head[1]&0xFF)==0x45
        && (head[2]&0xFF)==0xDF && (head[3]&0xFF)==0xA3;
}

Try / catch

try {
    reader.parse();
} catch (IOException e) {
    if (e.getMessage().contains("Fragment element not found")) {
        // header present but Segment missing — re-download the full file
        redownloadFullStream();
    } else throw e;
}

Prevention

When it happens

Trigger: Parsing a byte stream that has an EBML header but no Segment element — e.g. only the EBML header was downloaded, the Segment was cut off, or the data after the header is not a WebM Segment.

Common situations: A download that captured only the header/init bytes; a corrupted or partial file; a non-WebM file that coincidentally has a valid EBML header; a stream closed after the header.

Related errors


AI-assisted analysis of TeamNewPipe/NewPipe@9e8be09156 (2026-08-14). Data as JSON: /api/errors/681389be9edeca27. Report an issue: GitHub.