{"action":"created","issue":{"url":"https://api.github.com/repos/videojs/videojs-contrib-hls/issues/179","labels_url":"https://api.github.com/repos/videojs/videojs-contrib-hls/issues/179/labels{/name}","comments_url":"https://api.github.com/repos/videojs/videojs-contrib-hls/issues/179/comments","events_url":"https://api.github.com/repos/videojs/videojs-contrib-hls/issues/179/events","html_url":"https://github.com/videojs/videojs-contrib-hls/issues/179","id":47308720,"number":179,"title":"invalid mediaIndex causes live stream to freeze","user":{"login":"ssendev","id":450793,"avatar_url":"https://avatars.githubusercontent.com/u/450793?v=3","gravatar_id":"","url":"https://api.github.com/users/ssendev","html_url":"https://github.com/ssendev","followers_url":"https://api.github.com/users/ssendev/followers","following_url":"https://api.github.com/users/ssendev/following{/other_user}","gists_url":"https://api.github.com/users/ssendev/gists{/gist_id}","starred_url":"https://api.github.com/users/ssendev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ssendev/subscriptions","organizations_url":"https://api.github.com/users/ssendev/orgs","repos_url":"https://api.github.com/users/ssendev/repos","events_url":"https://api.github.com/users/ssendev/events{/privacy}","received_events_url":"https://api.github.com/users/ssendev/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-10-30T18:23:28Z","updated_at":"2015-01-08T14:10:24Z","closed_at":"2015-01-08T14:10:24Z","body":"I had a stream that would occasionally result in invalid mediaids. once i saw a way too high id. the other times it was caused by `translateMediaIndex()` when the new first sequence was higher than the currently active sequence (usually by one or two).\r\n\r\nthe following code tries to work around that. but i am not entirely sure it's correct since the error dosn't occur too often. (return 0?, why is the check by url comparing the last url(mediaIndex-1)? why return immediately if mediaIndex == 0?)\r\n\r\n```js\r\nvideojs.Hls.translateMediaIndex = function(mediaIndex, original, update) {\r\n  if (mediaIndex <= 0) { // this was === causing a broken index to be irrecoverable\r\n    return 0;\r\n  }\r\n\r\n  // ...\r\n\r\n  // put segments that were in original into update if this dosn't result in a gap in media sequence\r\n  if (newMediaIndex < 0) {\r\n    console.log('< newMediandex='+newMediaIndex);\r\n    if (original.mediaSequence + original.segments.length >= update.mediaSequence) {\r\n      i = update.mediaSequence - original.mediaSequence;\r\n      while(i-- > mediaIndex) {\r\n        update.segments.unshift(original.segments[i]);\r\n      }\r\n      console.log(update.segments);\r\n      return 0;\r\n    } else {\r\n      // there was a gap. start at the beginning of update\r\n      return 0;\r\n    }\r\n  }\r\n  if (newMediaIndex >= update.segments.length) {\r\n    console.log('> newMediandex='+newMediaIndex);\r\n    return 0;\r\n  }\r\n  return newMediaIndex;\r\n}\r\n```\r\n\r\nthis is the place the `mediaIndex` caused breakage;\r\n```js\r\nvideojs.Hls.prototype.drainBuffer = function(event) {\r\n  mediaIndex = segmentBuffer[0].mediaIndex;\r\n  segment = playlist.segments[mediaIndex];\r\n  if (segment.key) {\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/videojs/videojs-contrib-hls/issues/comments/69183321","html_url":"https://github.com/videojs/videojs-contrib-hls/issues/179#issuecomment-69183321","issue_url":"https://api.github.com/repos/videojs/videojs-contrib-hls/issues/179","id":69183321,"user":{"login":"ssendev","id":450793,"avatar_url":"https://avatars.githubusercontent.com/u/450793?v=3","gravatar_id":"","url":"https://api.github.com/users/ssendev","html_url":"https://github.com/ssendev","followers_url":"https://api.github.com/users/ssendev/followers","following_url":"https://api.github.com/users/ssendev/following{/other_user}","gists_url":"https://api.github.com/users/ssendev/gists{/gist_id}","starred_url":"https://api.github.com/users/ssendev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ssendev/subscriptions","organizations_url":"https://api.github.com/users/ssendev/orgs","repos_url":"https://api.github.com/users/ssendev/repos","events_url":"https://api.github.com/users/ssendev/events{/privacy}","received_events_url":"https://api.github.com/users/ssendev/received_events","type":"User","site_admin":false},"created_at":"2015-01-08T14:10:24Z","updated_at":"2015-01-08T14:10:24Z","body":"basically fixed. the problem is that my server has 30 seconds of content in the playlist with 10 seconds target duration so it starts playing at the edge of the playlist which can cause jumps when the playlist length varies. but it dosn't freeze anymore. so it'ts fixed but it would be cool if the start time could be configured"}}