не могу выбрать время поиска видео из полосы прокрутки - PullRequest
0 голосов
/ 01 октября 2018

Я хочу использовать видео тег и управлять им с помощью javascript, но он не работает так, как я хочу.

function vidplay(evt) {
  if (video.src == "") { // inital source load
    getVideo();
  }
  button = evt.target; //  get the button id to swap the text based on the state
  if (video.paused) { // play the file, and display pause symbol
    video.play();
    button.textContent = "||";
  } else { // pause the file, and display play symbol
    video.pause();
    button.textContent = ">";
  }
}
//  load video file from input field
function getVideo() {
  var d = document.getElementById('a4').innerHTML; // video file name

  // var fileURL = document.getElementById("videoFile").value;  // get input field
  var fileURL = d; // get input field
  if (fileURL != "") {
    video.src = fileURL;
    video.load(); // if HTML source element is used
    document.getElementById("play").click(); // start play
  } else {
    errMessage("Enter a valid video URL"); // fail silently
  }
}

var d в функции getVideo() похоже на "http://192.168.44.112/~/~.mp4"

Это видео было загружено на mongoDB, и я хочу его использовать.

Видео работает хорошо, но панель поиска не работает вообще, она только ищет время 0.

document.getElementById("rew").addEventListener("click", function() {
  setTime(-10);
}, false);

document.getElementById("fwd").addEventListener("click", function() {
  setTime(10);
}, false);


function setTime(tValue) {
  //  if no video is loaded, this throws an exception
  try {
    if (tValue == 0) {
      video.currentTime = tValue;
    } else {
      video.currentTime += tValue;
    }

  } catch (err) {
    // errMessage(err) // show exception
    errMessage("Video content might not be loaded");
  }
}

И когда я использую функцию setTime(), она отправляется на поиск времени 0, а я хочу искать на время, соответствующее тому, где я нажимаю.

Как я могу это сделать?

1 Ответ

0 голосов
/ 02 октября 2018

Я сделал этот быстрый пример, который вы можете протестировать и изучить, а затем вы можете просто применить аналогичную логику к приведенному выше коду.Надеюсь, это поможет вашей проблеме.

<video id="myVid" width="640" height="480" controls>
     <source src="yourVideoFile.mp4" type="video/mp4">
     Your browser does not support the video tag.
</video>


<script>

tValue = 0; //start at zero

myVid.addEventListener('seeking', function(e){ tValue = myVid.currentTime })

function setTime_FWD() 
{
    try 
    {
        if (tValue >= myVid.duration) { tValue = myVid.duration; }
        else { tValue += 10; myVid.currentTime = tValue; }
    } 
    catch (err) { errMessage("Video content might not be loaded"); }    
}

function setTime_RWD() 
{
    try 
    {
        tValue -= 10;
        if (tValue <= 0) { myVid.currentTime = tValue = 0; }
        else { myVid.currentTime = tValue; }
    }
    catch (err) { errMessage("Video content might not be loaded"); }
}


</script>


<br><br>

<button onclick="setTime_RWD()"> << </button>

<button onclick="setTime_FWD()"> >> </button>
...