当手机处于振动/静音状态时,音频曲目无法播放

时间:2016-03-18 04:04:22

标签: angularjs ionic-framework html5-audio spotify

我正在使用ngAudio来控制离子应用上的音轨(定制30秒预览)。这一切都在浏览器中膨胀。但是,在离子视图和实际的演示应用程序中,仅当我将手机振动切换转为非静音/振铃模式时,音轨才会流动。如果它处于振动模式,则用户听不到任何声音。我全身心地挖了,似乎无法解决这个问题。

这是我的服务:

 .factory('PlayerService', function(ngAudio) {

    var _play = function(show) {
        if (typeof audioObject === "undefined") {

            audioObject = ngAudio.load(show.track1_preview);

            console.log(audioObject);

            audioObject.play();

            audioObject.playing = show.id;

            return audioObject;
        } else if (audioObject.paused) {
            audioObject = ngAudio.load(show.track1_preview);
            audioObject.play();

            audioObject.playing = show.id;

            return audioObject;

        } else {
            audioObject.stop();
            audioObject = ngAudio.load(show.track1_preview);
            audioObject.play();

            audioObject.playing = show.id;

            return audioObject;

        }


    }

    var _pause = function(show) {

        audioObject.stop();

        audioObject.playing = '';

    }

    return {
        play: _play,
        pause: _pause
    };

这是控制器:

    $scope.playStream = function(show) {

        PlayerService.play(show);

        $scope.audioObject = audioObject; // this allow for styling the play/pause icons
    }

    $scope.pauseStream = function(show) {
        PlayerService.pause(show);
        $scope.audioObject = audioObject; // this allow for styling the play/pause icons

        //console.log($scope.audioObject);

    }

    $scope.togglePlayPause = function(show) {
        if (!$scope.audioObject || $scope.audioObject.paused) {
            $scope.playStream(show);
        } else if (show.track1_preview !== $scope.audioObject.id) {
            $scope.playStream(show);
        } else {
            $scope.pauseStream(show);
        }
    }

显然,如果有人不得不让手机振动以听到音轨,那么这是一种废话用户体验。

我想知道这是否与异步的东西和移动有关。我只是不知道。经过4个小时的捣乱后放弃。

0 个答案:

没有答案