Open Bug 1328024 Opened 7 years ago Updated 1 year ago

Changing src of <video> on Ctrl+Right shortcut causes new video to start from 5% from the beginning

Categories

(Toolkit :: Video/Audio Controls, defect)

defect

Tracking

()

People

(Reporter: arni2033, Unassigned)

References

Details

(Keywords: regression)

>>>   My Info:   Win7_64, Nightly 53, 32bit, ID 20161119030204 (2016-11-19)
STR_1:
1. Open url [1]
2. Execute code [2] in scratchpad or web console
3. Click on "Link1"
4. Pause the opened video, click in the center of timeline
5. Press Ctrl+Right, then (not necessary) immediately stop the video

AR:  New video starts from ~5% from the start
ER:  New video should start from the very beginning


STR_2:  (difference in Step 1)
1. Open local folder with at least 2 long videos (probably even 1 video is enough)
2. Execute code [2] in scratchpad or web console
3. Click on "Link1"
4. Pause the opened video, click in the center of timeline
5. Press Ctrl+Right, then (not necessary) immediately stop the video


Notes:
1) I wrote that script several years ago, only remember that it replaces "src" of video on Ctrl+Right
2) In case of long videos 5% from the start is several minutes, so it's quite noticeable

This is regression from bug 1274520. Regression range:
> https://hg.mozilla.org/integration/mozilla-inbound/pushloghtml?fromchange=952eae508967ae46d36909d179159f2a2205169c&tochange=2863702401b0927e2884c2b15476790265c1ff5c


[1]
> data:text/html,<a href="https://www.iandevlin.com/html5test/webvtt/v/upc-tobymanley.theora.ogg">Link1.webm</a><br><a href="https://www.iandevlin.com/html5test/webvtt/v/upc-tobymanley.theora.ogg">Link2.webm</a><br>

[2]
(function (){
  
  var i, Obj,
      Target = null,
      Extension = "",
      Links = [],
      CurrentNum = null,
      isVisible = false,
      isAutoplayList = true;
      video = document.createElement("video");
  for (i in Obj={
    /*loop:"",/**/
    autoplay:"",
    controls:"",
    style:"position:fixed; width:50%; height:50%; margin:auto; background:black; top:0%; bottom:0%; right:0%; z-index:1000; display:none; background:none no-repeat center center / auto 100% black;"
    +"width:80%; height:80%; left:0%;"
  })
    {video.setAttribute(i,Obj[i]);}
  video.onended=function(){ if (isAutoplayList) InitVideo(null,CurrentNum+1) };
  // video.style.backgroundImage = "url('file:///e:/Downloads/tumblr_nmu9blZtgH1relaado1_400.gif')";
  document.body.appendChild(video);
  
  var setTitle = function(cur){
    var getTimeString = function(time, delim){
      if (typeof time != "number") return typeof time;
      var hour = Math.floor(time/(60*60));
      time = time%(60*60);
      var min = Math.floor(time/60);
      var sec = time%60;
      return (hour?hour +delim: '') +(min>9||min<1||!hour?'':'0')+min +delim +(sec>9?'':'0')+sec;
    }
    var setTitleInner = function(){
      var time = Math.round(video.duration);
      document.title = cur+ " / "+ Links.length+ " of "+ Extension+ " ["+
        getTimeString(time,":")+ "] ["+ decodeURIComponent(video.src).split("/").slice(-1)[0]+ "]";
      video.removeEventListener('loadedmetadata', setTitleInner, false);
    }
    video.addEventListener('loadedmetadata', setTitleInner, false);
    document.title = cur+ " / "+ Links.length+ " of "+ Extension+ " ["+
      "--:--" + "] ["+ decodeURIComponent(video.src).split("/").slice(-1)[0]+ "]";
  }
  var InitVideo = function(href, num){
    if (typeof num == 'number'){
      num = (num + Links.length) % Links.length;
      CurrentNum = num; // update CurrentNum
      video.src = Links[num].href;
      setTitle(num+1);
    }
    else if(href){
      video.src = href;
      setTitle((CurrentNum+1) + " (?)");
    }
    else{
      console.log("scratchpad player by 2033: no arguments in InitVideo()\nOpenning the video...")
      // return; // do nothing if there's no valid track num or link
    }
    video.style.display = "inline";
    isVisible = true;
    // video.focus(); // I guess this isn't needed.
  }
  var CloseVideo = function(){
    video.pause();
    document.body.focus();
    video.style.display = "none";
    isVisible = false;
  }
  var UpdateOnClick = function(targ){        // returning "extension.isValid"
    Target = targ;                           // update Target
    var tempExt = /[.][^.]*$/.exec(Target.href);
    if (!tempExt || [".mp3",".webm",".mp4",".m4a", ".ogg"].indexOf(tempExt[0])==-1)
      return false;  // if extension isn't valid, then just try to load the link

    if (Extension!=tempExt[0]){
      Extension = tempExt[0];                // update Extension
      Links = [];
      var tempArr = document.querySelectorAll("A:not([onclick])[href$='"+ Extension +"']");
      for (i=0, L=tempArr.length; i<L; i++)  // update Links array
        Links.push(tempArr[i]);
    }
    return Links.indexOf(Target);            // update CurrentNum in InitVideo
  }
  
  var clickHandler = function(e){
    if (e.button != 0)
      return;
    if (e.target && e.target.tagName.toUpperCase()=="A"){
      e.preventDefault();
      InitVideo(e.target.href, UpdateOnClick(e.target));
    }
    // else if (e.target!=video)
    //   CloseVideo();
  };
  addEventListener('click',clickHandler,false);
  
  function ToggleReplay(){
    if (video.hasAttribute('loop')){
      video.removeAttribute('loop')
      video.style.backgroundColor = "#000";
    }
    else{
      video.setAttribute('loop','');
      video.style.backgroundColor = "#300";
    }
  }
  // Hotkeys
  var keyHandler = function(e){
    if (e.target.tagName=='textarea' ||
        e.target.tagName=='input'    ||
        e.target.hasAttribute("contenteditable"))
      return;
    switch( e.keyCode || e.charCode ){
      case e.DOM_VK_ESCAPE:{
        e.preventDefault();
        if (!isVisible){ 
          InitVideo();
          break;                   // player shouldn't be closed when it's invisible
        } else CloseVideo();
        if (e.shiftKey){           // destroy all11
          removeEventListener('click',clickHandler,false);
          removeEventListener('keypress',keyHandler,false);
          document.body.removeChild(video);
        }
        break;
      }
      case e.DOM_VK_UP:
      case e.DOM_VK_DOWN:
        if (!e.ctrlKey) break;
        e.preventDefault();
        Links[CurrentNum].scrollIntoView({behavior:'smooth'});
        break;
      case e.DOM_VK_LEFT:
        var increment = -1;
      case e.DOM_VK_RIGHT:
        if (!e.ctrlKey || !isVisible) break;
        e.preventDefault();
        var newNum = CurrentNum + (increment || 1);
        InitVideo(null,newNum);
        break;
      case 'r'.charCodeAt(0):
      case 'R'.charCodeAt(0):
      case 'к'.charCodeAt(0):
      case 'К'.charCodeAt(0):
        if (e.ctrlKey || !isVisible) break;
        ToggleReplay();
        break;
      case 'a'.charCodeAt(0):
      case 'A'.charCodeAt(0):
      case 'ф'.charCodeAt(0):
      case 'Ф'.charCodeAt(0):
        if (e.ctrlKey || !isVisible) break;
        isAutoplayList = !isAutoplayList;
        break;
    }
  }
  addEventListener('keypress',keyHandler,false);
})();

/* OLD */
/*
(function (){
  
  var video = document.createElement("video");
      video.setAttribute("style","position:fixed; width:50%; height:50%; margin:auto; background:black; top:0%; bottom:0%; right:0%; z-index:1000; display:none; background:none no-repeat center center / auto 100% black;");
      video.style.backgroundImage = "url('file:///e:/Downloads/tumblr_nmu9blZtgH1relaado1_400.gif')";
      video.setAttribute("autoplay","");
      video.setAttribute("controls","");
      document.body.appendChild(video);
  var handler = function(e){
    if (e.target && e.target.tagName.toUpperCase()=="A"){
      if (e.button != 0)
        return;
      e.preventDefault();
      video.src = e.target.href;
      video.style.display="inline";
    }
    else if (e.target!=video) {
      video.pause();
      video.style.display="none";
    }
  };
  addEventListener('click',handler,false);
  
})();
*/@ Xidorn Quan [:xidorn] (UTC+10):
It seems that this is a regresion caused by your change. Please have a look.
No longer blocks: 1277113
Component: Untriaged → Video/Audio Controls
Product: Firefox → Toolkit
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.