0

When I open the page in a browser, on occasions the video does not load and also if I refresh the page the video never loads, how can I fix these 2 issues?

This is the html for my video player

<video width="320" height="240" controls>
                <source id="audioFile" src="" type="video/mp4">
                Your brow

This is the javascript code which gets the name of the video file from the URL

function getUrlParameters(parameter, staticURL, decode){
            var currLocation = (staticURL.length)? staticURL : window.location.search,
            parArr = currLocation.split("?")[1].split("&"),
            returnBool = true;
            for(var i = 0; i < parArr.length; i++){
                parr = parArr[i].split("=");
                if(parr[0] == parameter){
                    return (decode) ? decodeURIComponent(parr[1]) : parr[1];
                    returnBool = true;
                }else{
                    returnBool = false;
                }
            }
            if(!returnBool) return false;
        }
        var parameter = getUrlParameters("audioFile", "", true);
        document.getElementById('audioFile').src = parameter;
        document.getElementById('url').content = parameter;
3
  • are you asking how to change the src? Commented Jun 29, 2014 at 17:47
  • No I'm asking how to fix the issues of the video not loading sometimes and when I refresh the page. Commented Jun 29, 2014 at 18:04
  • 1
    After you set the src, try running document.getElementById('video').load() Commented Jun 29, 2014 at 19:13

1 Answer 1

1

Dynamically modifying a source element and its attribute when the element is already inserted in a video or audio element will have no effect. To change what is playing, just use the src attribute on the media element directly <...>

The source element

Either change the src attribute of the video element (this will call the load() method implicitly):

var parameter = getUrlParameters("audioFile", "", true);
document.querySelector('video').src = parameter;

or call the load() method explicitly:

var parameter = getUrlParameters("audioFile", "", true);
document.getElementById('audioFile').src = parameter;
document.querySelector('video').load();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.