我正在使用angular-youtube-embed包在离子应用中显示YouTube视频。我有一个页面,我列出了所有文章,每个文章都有一个页面。当我在文章列表页面上尝试播放视频时工作正常,当我转到文章页面时,但当我回到文章列表页面时,我再也无法播放视频了我收到错误:
TypeError:youtubePlayer.playVideo不是函数
这是列出页面的文章的控制器:
$scope.playVideo = function(youtubePlayer, index) {
$scope.videoPlaying[index] = true;
youtubePlayer.playVideo();
};
$scope.$on('$ionicParentView.afterLeave', function(event, data) {
$scope.videoPlaying = false;
});
文章列出页面html:
<div class="iframe" ng-show="article.external_media.length > 0 && article.external_media.url != ''">
<img ng-hide="videoPlaying[$index]" class="img" ng-src="http://i1.ytimg.com/vi/{{ article.external_media[0].video_id }}/maxresdefault.jpg">
<youtube-video ng-show="!videoPlaying[$index]" video-url="article.external_media[0].original_url" player="youtubePlayer" player-vars="playerVars" class="iframe-video"></youtube-video>
<h1 ng-hide="videoPlaying[$index]">{{ article.title.split(' ', 7).join(' ') }}</h1>
<div ng-hide="videoPlaying[$index]" class="iframe-overlay" ng-click="playVideo(youtubePlayer, $index)"></div>
<img ng-hide="videoPlaying[$index]" ng-click="playVideo(youtubePlayer, $index)" class="play" src="icons/play.svg"/>
<img ng-hide="videoPlaying[$index]" ng-click="playVideo(youtubePlayer, $index)" class="playButton" src="icons/playRectangle.svg"/>
</div>