javascript - .play() not firing within directive using $watch -


i using buzz sound , familiar it's functionality. however, myself , mentor cannot figure out why sound file not firing within directive.

my directive:

(function() {     function clocktimer($interval, $window, stop_watch) {          return {             templateurl: '/templates/directives/clock_timer.html',             replace: true,             restrict: 'e',             scope: {},             link: function(scope, element, attributes) {                  scope.stop_watch = stop_watch; //see constants in app.js                 scope.startbutton = 'start work';                 scope.breakbutton = 'take break';                 scope.onbreak = false;  //boolean alternating displaying of work-time or break                 var mysound = new buzz.sound("/sounds/blue.mp3", {                   formats: ['mp3'],                   preload: true                 });                  // @desc initiates holder of completed work sessions.  increments 1 once timer hits 0                 var completedworksessions = 0;                 // @desc holds state $interval call                 var promise;                  scope.$watch('stop_watch.totalworktime', function() {                   if (scope.stop_watch.totalworktime === 0) {                     mysound.play();                     console.log(mysound);                     console.log("im listening");                   }                 }); 

my view

<section class="clock-container"> <div ng-show="!onbreak === true"> {{ stop_watch.totalworktime | clockformat }}   <button ng-click="startstopbutton(startbutton)" ng-show="!onbreak === true">{{ startbutton }}</button> </div> <div ng-hide="onbreak === false"> {{ stop_watch.totalbreaktime | clockformat }}   <button ng-click="takebreakbutton(breakbutton)">{{ breakbutton }}</button> </div> </section> 

buzz library included within index, i've tried adding scope beginning of mysound, tested .mp3 within test application (which worked fine), , still cannot sound play.

here console demonstrates $watch firing when suppose to:

sound {sound: audio, volume: 80} clocktimer.js:51 im listening 

any ideas or solutions? don't have controllers , think shouldn't need 1 since firing in console?

i removed formats: ['mp3'], buzz object. can either use formats: ['mp3'], or .mp3, not both.


Comments

Popular posts from this blog

mongodb - How to keep track of users making Stripe Payments -

javascript - Fire on return from form "Submit" -

javascript - Thinglink image not visible until browser resize -