停止在后台播放的其他视频播放新视频 [英] stop other video that is playing in background on play the new one

查看:42
本文介绍了停止在后台播放的其他视频播放新视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Videogular 来显示视频.当用户点击播放按钮到新视频时,你能帮我如何停止/暂停其他视频吗?因此,用户一次只能播放一个视频.

I am using Videogular to show video. could you please help me how to stop/pause other video when user click on play button to new one. So by this at a time user can play only one video at a time.

系统应自动停止后台正在播放的其他视频并播放新视频

The system should automatically stop other video that is playing in background and play the new one

谢谢

推荐答案

您可以为每个播放器单独获取所有 API 并监听状态变化:

You can get all the APIs separately for each player and listen for a change in the state:

<videogular ng-repeat="config in ctrl.videoConfigs" vg-player-ready="ctrl.onPlayerReady($API, $index)" vg-update-state="ctrl.onUpdateState($state, $index)">
    <!-- other plugins here -->
</videogular>

在你的控制器中:

'use strict';
angular.module('myApp').controller('MainCtrl',
    function ($sce) {
        // this.videoConfigs should have different configs for each player...

        this.players = [];

        this.onPlayerReady = function (API, index) {
            this.players[index] = API;
        };

        this.onUpdateState = function (state, index) {
            if (state === 'play') {
                // pause other players
                for (var i=0, l=this.players.length; i<l; i++) {
                    if (i !== index) {
                        this.players[i].pause();
                    }
                }
            }
        };
    }
);

这篇关于停止在后台播放的其他视频播放新视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆