Stop a song from playing on the same controller using $ locationProvider

0

The code is all right, but when I use $location.path('/minha-rota') for the same control, where it has a different view, which would be before starting a game, the sound is restarting, but on this route it does not call play, even after to stop it at the end of the script, without invoking $scope.playMusicTheme() , it resets ... as if it were restarting its instance ... how do I stop it without forcing a location.href ?

$scope.playMusicTheme = function() {
    $scope.audioMusicTheme.loop = true;
    $scope.audioMusicTheme.play();
};

$scope.pauseMusicTheme = function () {
    $scope.audioMusicTheme.pause();
};

$scope.stopMusicTheme = function () {
    $scope.audioMusicTheme.loop = false;
    $scope.audioMusicTheme.pause();
    $scope.audioMusicTheme.currentTime = 0;
    $('#audio_theme').remove();
};

$scope.setMusicTheme = function(file) {
    $scope.audioMusicTheme = document.createElement('audio');
    $scope.audioMusicTheme.setAttribute('src', file+'.mp3');
    $scope.audioMusicTheme.setAttribute('id', 'audio_theme');
    $scope.audioMusicTheme.addEventListener('canplay',$scope.playMusicTheme, false);
    $scope.audioMusicTheme.addEventListener('ended', $scope.playMusicTheme, false);
};

$scope.getSoundGame = function() {
   $scope.setMusicTheme("audios/musica");
};
    
asked by anonymous 15.06.2018 / 20:51

0 answers