Vineonardo
Vineonardo

Reputation: 183

Ionic Framework, Javascript function (JWPlayer) works only on page reload, how to solve this?

I'm trying to use JWPlayer to steam videos on an Ionic app. But I'm facing an issue.

The player only loads on page refresh and not when I'm browsing through the list of videos.

Following is the code of my controller


.controller('VideosCtrl', function($scope, $http) {
    $http.get('http://www.example.com/api/apps-videos').success(function(data, status, headers, config) {
        $scope.videos = data;
        $scope.video = data.filter(function(e){
          return e.id === $stateParams.videoId;
        })[0]; 


          jwplayer("jwPlayer").setup({
              file: $scope.video.playurl,
              image: $scope.video.video_image,
              skin: "bekle" 
          });
    });
})

Since I'm a noob, and don't know how to pass $scope variable to javascript, I've called jwplayer().setup() in the controller itself.

It works when page is refreshed but not again afterwords when the view is changed for any other video or is accessed from the list.

How do I solve this? Also, please let me know if there's a better way of doing this.

Thanks.

Upvotes: 1

Views: 1196

Answers (1)

Vineonardo
Vineonardo

Reputation: 183

It's solved now. I've turned off caching and started using local jwplayer js rather than one from CDN. It's all working fine now.

Thank you all.

Upvotes: 2

Related Questions