Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dashjs not defined error #1680

Closed
rafa8626 opened this issue Dec 2, 2016 · 17 comments
Closed

dashjs not defined error #1680

rafa8626 opened this issue Dec 2, 2016 · 17 comments

Comments

@rafa8626
Copy link

rafa8626 commented Dec 2, 2016

I have to following HTML files:

index.html

<!DOCTYPE html>
<html>
<head>
    <title>index</title>
    <style>
        .btn {
            display: inline-block;
            margin-bottom: 20px;
            padding: 10px;
            text-decoration: none;
            color: black;
            border: 2px solid black;
            border-radius: 4px;
        }
        .btn:hover {
            background-color: #aad6e5;
        }
    </style>
</head>
<body>
    <section>
        <a class="btn" id="a-dynamic-dash" href="video.html">Dynamic with dash</a>
        <a class="btn" id="a-nondynamic-dash" href="video.html">Non Dynamic with dash</a>
    </section>
    <div id="content-dynamic"></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script>
        $(function() {
            $('#a-dynamic-dash').click(function(e) {
                $('#content-dynamic').load($(this).attr('href'), function() {
                    initDash();
                });
    
                e.preventDefault();
                e.stopPropagation();
            });
    
            $('#a-nondynamic-dash').click(function(e) {
                initDash();
                e.preventDefault();
                e.stopPropagation();
            });
        });
    
        function initDash() { // init mediaelement
            $.getScript( "https://cdn.dashjs.org/latest/dash.all.min.js", function() {
                var player = dashjs.MediaPlayer().create();
                console.log(player);
            });
        }
    </script>
</body>
</html>

video.html

<!DOCTYPE html>
<html>
<head>
    <title>index</title>
    <style>
        .btn {
            display: inline-block;
            margin-bottom: 20px;
            padding: 10px;
            text-decoration: none;
            color: black;
            border: 2px solid black;
            border-radius: 4px;
        }
        .btn:hover {
            background-color: #aad6e5;
        }
    </style>
</head>
<body>
<section>
    <h1>Video</h1>
    <div><a class="btn" href="test.html">Back</a></div>
    <video muted controls preload="none" width="528px" height="297px">
        <source src="http://stijnheylen.com/mediaElementTest/video/animated-font/animated-font.mpd" type="application/dash+xml">
        <source src="http://stijnheylen.com/mediaElementTest/video/animated-font/animated-font.mp4" type="video/mp4">
    </video>
</section>
</body>
</html>

If I click the Non Dynamic with dash button I can see the console message; but if I click the other button I receive this error:
MediaPlayer.js:1855 Uncaught ReferenceError: dashjs is not defined

Interesting thing is that if I try another library using the exact same files and change what I expect to see once the script is loaded there are no issues. Example, if I change the initDash() to this:

function initDash() {
      $.getScript( "https://cdn.jsdelivr.net/hls.js/latest/hls.min.js", function() {
            var player = new Hls();
            console.log(player);
      });
}

I can see properly the console when using the Dynamic button. Is there something I am missing?

@davemevans
Copy link
Contributor

davemevans commented Dec 2, 2016

Whilst I hate making comments like this, this WFM in Chrome 55 on Win 7 (ie I don't get that console error)

I have to apologise as I realised that I had clicked the working test case first which caused the library to be loaded into the context when I subsequently tried the other button.

@rafa8626
Copy link
Author

rafa8626 commented Dec 2, 2016

I experienced this on mac OS sierra using Chrome v54.0.2840.98 and also FF v50.0.2

@rafa8626
Copy link
Author

rafa8626 commented Dec 2, 2016

Another issue experienced the same with OSX El Capitan using Chrome(Version 55.0.2883.75), Firefox(50.0.2) and Safari.

@dsparacio
Copy link
Contributor

If you remove all the jquery stuff around the dash.js creations does it fix it

$.getScript( "https://cdn.dashjs.org/latest/dash.all.min.js", function() {
var player = dashjs.MediaPlayer().create();

@rafa8626
Copy link
Author

rafa8626 commented Dec 2, 2016

@AkamaiDASH Yeah that's basically using a non-AJAX approach like pressing the second button, but I need to bring markup from AJAX to insert the video tag first and then load the library to continue with other operations. And that's where it fails. But compared to other libraries, this one has something that is not being loaded for some reason if I try to load it once an AJAX request has been successful

@dsparacio
Copy link
Contributor

Thanks , I am trying to verify this issue within a certain scope (Jquery) VS wide spread issue since we are trying to freeze code and get RC1 out today.

@rafa8626
Copy link
Author

rafa8626 commented Dec 2, 2016

I see. Thanks for looking at this. Keep me posted about your findings please

@JibberJim
Copy link

JibberJim commented Dec 2, 2016 via email

@rafa8626
Copy link
Author

rafa8626 commented Dec 2, 2016

The thing is I tried using vanilla JavaScript to perform an AJAX request and do what you said and still experienced the same issue. I used jQuery to simplify the HTML

@JibberJim
Copy link

JibberJim commented Dec 2, 2016 via email

@davemevans
Copy link
Contributor

Further to this, you don't even need to call dashjs.MediaPlayer.create once you have the script loaded properly since you have added <source src="http://stijnheylen.com/mediaElementTest/video/animated-font/animated-font.mpd" type="application/dash+xml">. This will cause the MediaPlayer will be created automatically by the MediaPlayerFactory.

@rafa8626
Copy link
Author

rafa8626 commented Dec 2, 2016

Here's the link where I see the issue http://stijnheylen.com/mediaElementTest/

@rafa8626
Copy link
Author

rafa8626 commented Dec 2, 2016

The implementation of Dash is inside te mediaelement.js file

@JibberJim
Copy link

JibberJim commented Dec 2, 2016 via email

@davemevans
Copy link
Contributor

Related: #1496

@rafa8626
Copy link
Author

rafa8626 commented Dec 2, 2016

Thanks for looking at this. I'll check the approach you proposed and keep you posted. Please keep me posted as we'll about fixing this; this is a key element in the project and it will be really nice to get it sorted out to cover most of the known scenarios

@rafa8626
Copy link
Author

rafa8626 commented Dec 9, 2016

Thanks for fixing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants