如何使用 videogular 和 ionic v1 在 Android 上自动播放视频?

How to autoplay videos on Android using videogular and ionic v1?

在我的项目中,我试图在 Android 设备上自动播放视频。目前,我有以下内容:

        <videogular vg-player-ready="ionicVideoCtrl.onPlayerReady($API)"
                    vg-complete="ionicVideoCtrl.onCompleteVideo()"
                    vg-theme="ionicVideoCtrl.config.theme"
                    vg-autoplay="ionicVideoCtrl.config.autoPlay">
            <vg-media vg-src="ionicVideoCtrl.config.sources"
                      vg-youtube="{{ ionicVideoCtrl.config.youTubeOptions }}"
                      vg-native-controls="ionicVideoCtrl.isYouTube">
            </vg-media>

            <vg-buffering data-ng-if="!ionicVideoCtrl.config.isYouTube"></vg-buffering>
            <vg-controls data-ng-if="!ionicVideoCtrl.config.isYouTube"
                         vg-autohide="ionicVideoCtrl.config.autoHide"
                         vg-autohide-time="ionicVideoCtrl.config.autoHideTime">
                <vg-play-pause-button></vg-play-pause-button>
                <vg-time-display>{{ currentTime | date:'mm:ss' }}</vg-time-display>
                <vg-scrub-bar>
                    <vg-scrub-bar-current-time></vg-scrub-bar-current-time>
                </vg-scrub-bar>
                <vg-time-display>{{ timeLeft | date:'mm:ss' }}</vg-time-display>
                <vg-volume>
                    <vg-mute-button></vg-mute-button>
                    <vg-volume-bar></vg-volume-bar>
                </vg-volume>
                <vg-fullscreen-button></vg-fullscreen-button>
            </vg-controls>

            <vg-poster data-ng-if="!ionicVideoCtrl.config.isYouTube || ionicVideoCtrl.isLoadingVideo"
                       vg-url='ionicVideoCtrl.config.plugins.poster'></vg-poster>

            <!--<vg-analytics vg-track-info="ionicVideoCtrl.config.plugins.analytics"></vg-analytics>-->

            <vg-overlay-play data-ng-if="!ionicVideoCtrl.config.isYouTube"></vg-overlay-play>
        </videogular>

其中 ionicVideoCtrl.config.autoPlay = trueionicVideoCtrl.config.youTubeOptions = 'rel=0;showinfo=0;autoplay=1;'

这在我的浏览器中运行良好,但在 Android 设备上运行不正常。这是受OS的限制吗?有解决方法吗?

我从未使用过 Videogular,但 Ionic 应用程序只是普通的 HTML5 网络应用程序。

因此,此处适用任何其他网页的规则。

请参阅 official documentation 说明

Playback will start automatically for a video element once it comes into view if both autoplay and muted are set, and playback of muted videos can be initiated pragmatically with play(). Previously, playback on mobile had to be initiated by a user gesture, regardless of the muted state.

文档中还可以找到以下代码:

<video autoplay muted>
    <source src="video.webm" type="video/webm" />
    <source src="video.mp4" type="video/mp4" />
</video>

所以是的,这确实是一个 OS 限制