2

I am trying in several ways to start jwplayer in my web app in which i use angularjs.. I need to pass at file option a dynamic link of the file. In my controller i can have the dynamic link with a simple function

getVideoStreaming: function(file) {
    $scope.fileName = file.name;
    $scope.documentId = document.id;
    $scope.videoSrc = "http://mywebserver.com/" + $scope.fileName;
},

this function is called when i click in a button that opens a modal in which i want show the video.

<button data-uk-modal="{target:'#videoPlayer'}" data-ng-click="files.getVideoStreaming(file)"> Open video </button>

Now the question.. how can i pass this variable to my modal? According to the jwplayer basic configuration this is what i should do:

<!-- dialog video -->
<div id="videoPlayer" class="uk-modal">
    <div class="uk-modal-dialog" style="width: 680px!important;">
        <a class="uk-modal-close uk-close"></a>
        <h3 class="uk-panel-title">
            <i class="zmdi zmdi-collection-text"></i>
            {{docName}}
        </h3>
        <div id="myElement">Loading the player...</div>

        <script type="text/javascript">
            var playerInstance = jwplayer("myElement");
            playerInstance.setup({
                file: "http://example.com/uploads/file.mp4",
                image: "http://example.com/uploads/myPoster.jpg",
                width: 640,
                height: 360,
                title: 'Basic Video Embed',
                description: 'A video with a basic title and description!'
            });
        </script>
    </div>
</div>

but of course, as i've just said, i need file dynamic. Is it possible find a solution to this?

1 Answer 1

2

I have not tried to use JWPlayer from within a modal, but the directive I wrote should work for you. If not, then maybe you can reverse engineer and adapt. See how I use ng-src for the video file, with the directive is watching for a change.

ng-jwplayer

or bower install ng-jwplayer --save

Then use like:

<jwplayer ng-src="{{ videoSrc }}"
         player-options="options"
         player-id="myPlayer1">
</jwplayer>

and move your options to

...
$scope.videoSrc = "http://mywebserver.com/" + $scope.fileName;
$scope.options = {
  image: "http://example.com/uploads/myPoster.jpg",
  width: 640,
  height: 360,
  title: 'Basic Video Embed',
  description: 'A video with a basic title and description!'
}

The package also uses a service to ensure the global jwplayer does not get instantiated multiple times.

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.