【问题标题】:How to Parse M3U8 file in Android如何在 Android 中解析 M3U8 文件
【发布时间】:2019-12-13 06:56:15
【问题描述】:

我需要在 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="Bein ENT - OSN",BEIN MOVIE 4 http://maxtvv.abdou123.com:8080/live/localhd/211VGH699/1321.m3u8

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

【问题讨论】:

    标签: android m3u8 m3u iptv


    【解决方案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.");
      }
    

    【讨论】:

      猜你喜欢
      • 2013-06-02
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      • 2012-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多