【问题标题】:In Ionic framework I am using iframe to autoplay youtube video but its not working in android在 Ionic 框架中,我使用 iframe 自动播放 youtube 视频,但它在 android 中不起作用
【发布时间】:2015-04-09 12:09:38
【问题描述】:

我是 Ionic 框架的新手。

我正在使用 iframe 嵌入 YouTube 视频,还使用 ​​?autopaly=1 自动播放视频,它在浏览器中运行,但在 Android 中不运行。

【问题讨论】:

  • 你能给我看看你的代码示例吗?

标签: iframe youtube-api ionic-framework


【解决方案1】:

嵌入的 youtube 视频可以在 Ionic 中使用 $scope 在 controllers.js 中定义 URL,然后在 app.js 中创建一个过滤器。

controllers.js 的代码

.controller('FooCtrl', function($scope,$stateParams) {
   $scope.videoSet = [
    [
      { url: 'https://www.youtube.com/embed/oHg5SJYRHA0?rel=0&autoplay=1', t: '3:33'}
    ]
   ];
   $scope.videoId = $stateParams.videoId;
})

app.js 的代码

.filter('trustAsResourceUrl', ['$sce', function($sce) {
    return function(val) {
        return $sce.trustAsResourceUrl(val);
    };
}])

foo.html 模板的代码

<ion-view view-title="Youtube Videos">
<ion-content ng-repeat="video in videoSet[videoId]">
    <ion-list>
        <div class="card">
            <ion-item>
                <iframe src="{{video.url | trustAsResourceUrl}}" frameborder="0" width="560" height="315"></iframe>
            </ion-item>
        </div>
    </ion-list>
</ion-content>
</ion-view>

希望这对你有用

【讨论】:

  • 嗨,我使用您的示例代码使我的 youtube 播放器视频正常工作,除了当我通过 Ionic View 在 iPhone 上运行它时,我没有任何来自 youtube 电影的声音。或许你知道为什么?
  • 嗨,很高兴听到它有效!我发现使用 html5 apis 和 Ionic View 结合的问题很多,无论是在 Android 还是 iOs 上,所以它可能与此有关......你可以在这里找到更多信息,或者开始一个新问题:@ 987654321@ 这是另一个链接,您可以在其中找到您的解决方案:forum.ionicframework.com/t/… 如果有什么适合您的,请告诉我,干杯
猜你喜欢
  • 2013-09-11
  • 2014-12-02
  • 1970-01-01
  • 1970-01-01
  • 2015-04-11
  • 2018-12-17
  • 2018-12-17
  • 2011-04-23
  • 2015-03-18
相关资源
最近更新 更多