Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Dynamic JWPlayer Single-Line Embed Question


Good afternoon,

I am currently a jwplayer user with commercial license and I am trying to build up a web app using dynamic JWPlayer Single-Line Embed.

Ex: <script src="//content.jwplatform.com/players/MEDIAID-PLAYERID.js"> </script>

Based on the video is selected, different MEDIAID is feeding to the html page. However, I have tried variety method, including create a script placeholder on my html but it doesn't seem to work. I am always getting this error for some reasons and I couldnt be able to work around.

The error that I get is
"Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened."

"uncaught typeerror jwplayer(...).setup is not a function"

This is what I have so far for testing purpose:

index.html

<body ng-app="myApp" ng-controller="HomeCtr">
....
<div class="moreTest">
<script ng-src="//content.jwplatform.com/players/{{player}}"></script>
</div>
</body>


app.js
app.controller('HomeCtr', function ($scope) {
console.log("I am in HomeCtr ");
$scope.player = "AAAAAA-BBBBBB.js?sig=CCCCCCCCCCCC&exp=DDDDDDD"


OR

// var fileref = document.createElement('script');
// fileref.setAttribute("type", "text/javascript");
// fileref.setAttribute("src", "//content.jwplatform.com/players/AAAAAA-BBBBBB.js?sig=CCCCCCCCCCCC&exp=DDDDDDD);
// alert(fileref);
// document.getElementsByTagName("head")[0].appendChild(fileref);


Any helps will be appreciated

5 Community Answers

Long Nguyen

User  
0 rated :

Add to my question:

If I am placing the embedded scripts directly into html, it works fine. But I want to inject different MEDIAID based on user's selection.

I would prefer a single line embedded script rather than to create an instance of jwplayer.

Thank you for your time

LN

George

JW Player Support Agent  
0 rated :

Hello Long,

Based on your error
“Failed to execute ‘write’ on ‘Document’: It isn’t possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.”

You may want to change your approach. Perhaps you could just call jwplayer().setup() or jwplayer().load() when you click on a media id because that will load the new content into the previously instantiated jwplayer.

Long Nguyen

User  
0 rated :

Hello George,

Thank you for your replied, I have done what you have mentioned above and it works perfectly on the previous version of my application but for next version, I want to use a Single-Line Embed Script tag for the embedded video, which avoids me from creating an instance of jwplayer. I am wondering if you have any other workaround for it?

My goal is to inject Single-Line Embed Script into .html page based on user's selection

Thank you so much for your time and I am looking forward to hear from you soon

LN

Long Nguyen

User  
0 rated :

If you can provide a sample/example, that is awesome

LN

George

JW Player Support Agent  
0 rated :

Hello Long,

That is a bit out of the scope of support in this case. Your issues are with plain javascript and the rules browsers have applied. This is not an error with the player.

The error:
“Failed to execute ‘write’ on ‘Document’: It isn’t possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.”
Will most likely fire unless you find a workaround, I do not have a solution for your suggested method and error.

This question has received the maximum number of answers.