Hướng dẫn javascript video player timeline - dòng thời gian của trình phát video javascript

I created a player using HTML/JS/CSS, which I uploaded , specific use on the real server , the player works correctly on high resolution [PC], but not working properly on mobile, for example, the preview does not work when hovering over the timeline with finger. I would like advice on how to fix it.





Your user agent does not support the HTML5 Video element.

js - timeline part

// Timeline

timelineContainer.addEventListener["mousemove", handleTimeLineUpdate]
timelineContainer.addEventListener["mousedown", toggleScrubbing];

document.addEventListener["mouseup", e => {
    if[isScrubbing] toggleScrubbing[e]
}]

document.addEventListener["mousemove", e => {
    if[isScrubbing] handleTimeLineUpdate[e]
}]


let isScrubbing = false;
let wasPaused;

function toggleScrubbing[e]{
    const rect = timelineContainer.getBoundingClientRect[];
    const percent = Math.min[Math.max[0, e.x - rect.x], rect.width]/rect.width;

    isScrubbing = [e.buttons & 1] === 1;
    videoContainer.classList.toggle["scrubbing", isScrubbing]
    if[isScrubbing]{
        wasPaused = video.paused;
        video.pause[];
    } else {
        video.currentTime = percent * video.duration;
        if[!wasPaused] video.play[];
    }
    handleTimeLineUpdate[e];
}


function handleTimeLineUpdate[e]{
    const rect = timelineContainer.getBoundingClientRect[];
    // e.x = position mous, rect.x = position timeline
    const percent = Math.min[Math.max[0, e.x - rect.x], rect.width]/rect.width;

    // /10 protože mám po 10 vterinach 
    const previewImgNumber = Math.max[1, Math.floor[[percent*video.duration]/10]];
    const previewImgSrc = `video/preview${previewImgNumber}.jpg`;
    // Uložení cesty k obrazku
    previewImg.src = previewImgSrc;
    timelineContainer.style.setProperty["--preview-position",percent];

    if[isScrubbing]
    {
        e.preventDefault[];
        thumbnailImg.src = previewImgSrc;
        timelineContainer.style.setProperty["--progress-position", percent];
    }
}

This work on PC browser but not well on mobile

Thằng này thì khỏi phải nói rồi, nổi từ khi còn dùng Flash cơ mà. Giờ nó support cả HTML 5 và FLash luôn, tự detect thiết bị và trình duyệt để render ra player phù hợp. Hầu như các site phim online của Việt Nam mình đều dùng player này cả.

videojs
Trong phần này, mình sẽ hướng dẫn các bạn tạo một phayer cực đơn giản với API của HTML 5. Nhưng trước tiên chúng ta cần phải có ui của một media player cái đã.

Mã:





Your user agent does not support the HTML5 Video element.

Tại sao lại phải nằm trong play? Đơn giản vì khi chúng ta ấn vào nút play, thì timeline sẽ bắt đầu hoạt động rồi. Tuy nhiên, còn một điểm mà chúng ta cần giải quyết đó là? Chuyện gì xảy ra nếu người dùng muốn tua nhanh video bằng cách kéo điểm neo? Bây giờ chúng ta sẽ giải quyết vấn đề đó.

Mã:

play
pause
full screen


Current: 0 / 

Chủ Đề