I need to call a JavaScript method from angular.js when a sound ends. I want to call the check()
function which is inside in the ready
method.
app.controller("myCtrl",function($scope,ngAudio,$document)
{
$scope.audio;
$scope.play=function(myAud)
{
$scope.audio = new Audio(myAud)
$scope.audio.play();
$scope.audio.onended=function()
{
console.log("called");
$scope.audio = new Audio('aud1.mp3');
$scope.audio.play();
$scope.check();
}
}
$scope.stop=function()
{
$scope.audio.stop()
}
$document[0].addEventListener("visibilitychange", function() {
var doucmentHidden = document.hidden;
if (doucmentHidden)
{
console.log("called");
$scope.audio.pause();
}
else
{
console.log("called");
$scope.audio.play();
}
}, false);
});
</script>
<script>
$(document).ready(function()
{
var aud= angular.element(document.getElementById('container')).scope();
aud.play('aud.mp3');
function check()
{
console.log("called1");
}
});
</script>
How can I trigger the check()
function when I need to?