Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play a sound in angularjs

Using an API to obtain the url of the sound to play in audio tag
View

<img src="../img/play.svg" alt="Play" ng-click="playSound('exampleWord')" width="48"/>

Controller:

$scope.playSound=function(input){
    $scope.audio={};
    soundFetch.getSound(input).success(function(data){
        $scope.audio=data;
    });
}

The soundFetch is the service to call the getSound function. The returning data is the url of the song. How can I play the sound after clicking the img tag. Currently getting an error Error: [$interpolate:interr]

like image 983
Akansh Avatar asked Jun 17 '15 02:06

Akansh


1 Answers

    $scope.playAudio = function() {
        var audio = new Audio('audio/song.mp3');
        audio.play();
    };
like image 136
RJH Avatar answered Sep 28 '22 09:09

RJH