How to refresh after updating the new video?

3

In my vision, I have an old video, when I upload new video, I want to automatically reload a new video after "upload".

View :

<div id="embed_video" class="embed-responsive embed-responsive-16by9">
    <video class="embed-responsive-item" controls>
        <source src="/Files/GetVideo?id=2" type="video/mp4">
        Seu navegador não suporta vídeo em HTML5.
    </video>
</div>

Javascript :

 $('#embed_video video').get(0).load();

JavaScript code only works the first time, the second time the video does not update, it stays as old.

Controller :

public ActionResult GetVideo(int id)
{
    using (var ctx = new Entities())
    {
        var result = ctx
            .Video
            .FirstOrDefault();    
        byte[] video_byte = result.Video;    
        return new RangeFileContentResult(video_byte, "video/mp4", "NomeDoArquivo.mp4", date);
    }
}

Any solution?

From now on, I'm glad.

    
asked by anonymous 24.10.2016 / 14:43

2 answers

1

This is because it is cached because the name is probably the same, one way to solve is to use a random querystring (which does not repeat itself as something based on timestamp ).

However, you must first get the currentSrc ( link ) , something like:

var videourl = $('#embed_video video').prop("currentSrc");

Then clean the querystring:

videourl = videourl.replace(/\?(.*?&)?_=\d+$/, "?$1");

And apply the new:

videurl = videorl + "_=" + Date.now();

You can do a function like this:

function updateVideo(query, play) {
    var el = $(query).get(0); //usei o .get para ficar mais "limpo" o código, mas o resultado é indiferente no final

    if (!el) alert('Não encontrado'); return;

    var videourl = el.currentSrc;

    videourl = videourl.replace(/\?(.*?&)?_=\d+$/, "?$1");
    videourl = videourl + (videourl.indexOf("?") !== - 1 ? "&" : "?");
    videourl = videourl + "_=" + Date.now();

    el.pause();
    el.src = videourl;

    if (play) el.play(); //o play já executa o load
}

The usage would look something like:

updateVideo('#embed_video video', true);

Or without autoplay:

updateVideo('#embed_video video', false);
    
22.07.2018 / 21:12
0

I think I answered the same question or a very similar one yesterday ... but below:

document.getElementById("VideoReload").load();
    
26.10.2016 / 18:39