0

我需要在 android studio 中解析 m3u8 内容。我尝试了几次使用 github 库,例如 open-m3u8。但我无法解析这个。请为我解决这个问题。

谢谢。

我尝试了几次使用 github 库,例如 open-m3u8。但这说明格式不好。我不确定这个异常错误。

EXTM3U

EXTINF:-1 tvg-id="beIN Movies 1 HD" tvg-name="BEIN MOVIE 1" tvg-logo="https://4.bp.blogspot.com/-lLLGwGe0SU0/VvfF-Wf-PgI/AAAAAAAD1w /4wuF8M2X9YsckWaAfPSXdIPTDVgcPaSnQ/s1600/be_in_movies_1_hd.png" group-title="Bein ENT - OSN",BEIN MOVIE 1 http://maxtvv.abdou123.com:8080/live/localhd/211VGH699/1324.m3u8

EXTINF:-1 tvg-id="beIN Movies 2 HD" tvg-name="BEIN MOVIE 2" tvg-logo="https://4.bp.blogspot.com/-QUXStVW8y4c/WDT5VaV7I0I/AAAAAAAAC20/7X43vlEpcDoZPINfDi3MonZ-LpPcsaa -QCLcB/s1600/Movies2HD.jpg" group-title="Bein ENT - OSN",BEIN MOVIE 2 http://maxtvv.abdou123.com:8080/live/localhd/211VGH699/1323.m3u8

EXTINF:-1 tvg-id="beIN Movies 3 HD" tvg-name="BEIN MOVIE 3" tvg-logo="http://aya.sy/images/services/iptv/Bein_Movies_3.png" group-title= “Bein ENT - OSN”,BEIN MOVIE 3 http://maxtvv.abdou123.com:8080/live/localhd/211VGH699/1322.m3u8

EXTINF:-1 tvg-id="beIN Movies 4 HD" tvg-name="BEIN MOVIE 4" tvg-logo="http://aya.sy/images/services/iptv/Bein_Movies_4.png" group-title= “贝因耳鼻喉 - OSN”,贝因电影 4 http://maxtvv.abdou123.com:8080/live/localhd/211VGH699/1321.m3u8

我应该通过这个解析获得 4 通道数据。

4

1 回答 1

1

ExoPlayer 包含一个 m3u8 HLS 播放列表解析器,源代码可用:

顶层看起来像这样 - 您可以看到它遍历 m3u8 文件中的每一行,有时称为清单,并确定该行中的信息类型以允许它正确解释每一行:

@Override
  public HlsPlaylist parse(Uri uri, InputStream inputStream) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    Queue<String> extraLines = new ArrayDeque<>();
    String line;
    try {
      if (!checkPlaylistHeader(reader)) {
        throw new UnrecognizedInputFormatException("Input does not start with the #EXTM3U header.",
            uri);
      }
      while ((line = reader.readLine()) != null) {
        line = line.trim();
        if (line.isEmpty()) {
          // Do nothing.
        } else if (line.startsWith(TAG_STREAM_INF)) {
          extraLines.add(line);
          return parseMasterPlaylist(new LineIterator(extraLines, reader), uri.toString());
        } else if (line.startsWith(TAG_TARGET_DURATION)
            || line.startsWith(TAG_MEDIA_SEQUENCE)
            || line.startsWith(TAG_MEDIA_DURATION)
            || line.startsWith(TAG_KEY)
            || line.startsWith(TAG_BYTERANGE)
            || line.equals(TAG_DISCONTINUITY)
            || line.equals(TAG_DISCONTINUITY_SEQUENCE)
            || line.equals(TAG_ENDLIST)) {
          extraLines.add(line);
          return parseMediaPlaylist(
              masterPlaylist, new LineIterator(extraLines, reader), uri.toString());
        } else {
          extraLines.add(line);
        }
      }
    } finally {
      Util.closeQuietly(reader);
    }
    throw new ParserException("Failed to parse the playlist, could not identify any tags.");
  }
于 2019-08-08T14:29:44.623 回答