Exemplo n.º 1
0
  private void createPlaylist() {
    String showName = MediaFileAPI.GetMediaTitle(mediaFile);
    int numberOfMediaFileSegments = MediaFileAPI.GetNumberOfSegments(mediaFile);
    Log.debug("Number of media file segments: " + numberOfMediaFileSegments);

    for (int i = 0; i < numberOfMediaFileSegments; i++) {
      // get length of current media file segment
      long mediaFileSegmentDurationInMillis = MediaFileAPI.GetDurationForSegment(mediaFile, i);
      long mediaFileSegmentDurationInSeconds =
          mediaFileSegmentDurationInMillis / 1000; // milliseconds to seconds
      Log.debug(
          "mediaFileSegmentDurationInMillis (" + i + "): " + mediaFileSegmentDurationInMillis);
      Log.debug(
          "mediaFileSegmentDurationInSeconds (" + i + "): " + mediaFileSegmentDurationInSeconds);

      int sequence = 0;
      for (int j = 0; j < mediaFileSegmentDurationInSeconds; j += SegmentPlaylist.TARGET_DURATION) {
        long currentDuration =
            Math.min(SegmentPlaylist.TARGET_DURATION, mediaFileSegmentDurationInSeconds - j);

        Segment newSegment = new Segment(currentDuration, sequence, i, showName);

        segmentList.add(newSegment);

        sequence++;
      }
    }
    if (segmentList != null) {
      Log.debug("segmentList size: " + segmentList.size());
    }
  }
Exemplo n.º 2
0
  public String toString() {
    StringBuilder sb = new StringBuilder();

    String showName = MediaFileAPI.GetMediaTitle(mediaFile);
    int numberOfMediaFileSegments = MediaFileAPI.GetNumberOfSegments(mediaFile);
    int segmentCount = (isFileCurrentlyRecording) ? segmentList.size() - 1 : segmentList.size();
    Log.debug("Show: " + showName);
    Log.debug("MediaFileId: " + mediaFileId);
    Log.debug("Number Of MediaFile segments: " + numberOfMediaFileSegments);
    Log.debug("Is file currently recording: " + isFileCurrentlyRecording);
    Log.debug("Number of playlist segments: " + segmentCount);

    sb.append("#EXTM3U" + LINE_TERM);
    Log.debug("#EXTM3U");
    sb.append("#EXT-X-TARGETDURATION:" + TARGET_DURATION + LINE_TERM);
    Log.debug("#EXT-X-TARGETDURATION:" + SegmentPlaylist.TARGET_DURATION);
    //        sb.append("#EXT-X-MEDIA-SEQUENCE:1" + LINE_TERM);
    //        Log.debug("#EXT-X-MEDIA-SEQUENCE:1");

    for (int i = 0; i < segmentCount; i++) {
      Segment currentSegment = segmentList.get(i);
      Segment previousSegment = (i == 0) ? null : segmentList.get(i - 1);
      Segment nextSegment = (i == segmentCount - 1) ? null : segmentList.get(i + 1);
      String str = currentSegment.toString();
      sb.append(str);

      // first or last playlist segment for each media file segment
      // printing the whole playlist makes the log harder to read
      if ((previousSegment == null)
          || (nextSegment == null)
          || (previousSegment.mediaFileSegment != currentSegment.mediaFileSegment)
          || (currentSegment.mediaFileSegment != nextSegment.mediaFileSegment)) {
        Log.debug(str);
      }
    }

    //      #EXT-X-MEDIA-SEQUENCE:<number>
    //      #EXT-X-PROGRAM-DATE-TIME:<YYYY-MM-DDThh:mm:ssZ>
    //      #EXT-X-ALLOW-CACHE:<YES|NO>
    //      #EXT-X-STREAM-INF

    if (!isFileCurrentlyRecording) {
      sb.append("#EXT-X-ENDLIST" + LINE_TERM);
      Log.debug("#EXT-X-ENDLIST");
    }
    return sb.toString();
  }