angular-soundmanager2 icon indicating copy to clipboard operation
angular-soundmanager2 copied to clipboard

Error when sound finishes

Open diegolz opened this issue 10 years ago • 10 comments

Hi! First of all I'm new to soundmanager but I get this error after the track ends: Uncaught TypeError: Cannot read property 'get' of undefined angular-soundmanager2.js:6086 init.soundManager.setup.defaultOptions.onfinish angular-soundmanager2.js:3179 (anonymous function)angular-soundmanager2.js:3466 wrapCallback angular-soundmanager2.js:3178 SMSound._onfinishangular-soundmanager2.js:3801 (anonymous function) angular-soundmanager2.js:3719 (anonymous function)

The problem seems to be the autoPlay parameter that is seted to true and since I don't have anymore tracks the error arises. Is there a way to set this parameter via attribute or something like that ?

diegolz avatar Feb 18 '15 20:02 diegolz

The error disappears when I create the sound via soundManager.createSound. I think I'll try to override the onfinish function in order to set the isPlaying var to false after video ends.

diegolz avatar Feb 18 '15 20:02 diegolz

I have solved this by including $injector to the ngSoundManager.factory and changed var angularPlayer = injector.get('angularPlayer'); to var angularPlayer = $injector.get('angularPlayer'); (you can get rid of the lines above within the if statement)

melino avatar Mar 30 '15 20:03 melino

I had this same issue - its because I was using data-ng-app not ng-app in my so the injector couldn't find my app.

You either need to amend [ng-app] below or change your html attribute.

 onfinish: function() {
                            soundManager._writeDebug(this.id + ' finished playing');
                            if(autoPlay === true) {
                                //play next track if autoplay is on
                                //get your angular app
                                var elem = angular.element(document.querySelector('[ng-app]'));
                                //get the injector.
                                var injector = elem.injector();
                                //get the service.
                                var angularPlayer = injector.get('angularPlayer');
                                angularPlayer.nextTrack();
                                $rootScope.$broadcast('track:id', currentTrack);
                            }
                        }

apricot13 avatar Apr 10 '15 14:04 apricot13

Shouldnt this be fixed by the maintainer

neoighodaro avatar Apr 17 '15 08:04 neoighodaro

@diegolz @apricot13 @melino can you please do a pull request if possible? I can't replicate this issue, so not sure what is wrong.

perminder-klair avatar Apr 22 '15 18:04 perminder-klair

I've recreated the issue in plunker: http://plnkr.co/edit/hjlagTWsp4XtAFZCCaKs

to replicate - click 'play all' and wait until the first track finishes - the error is triggered when the first track finishes.

apricot13 avatar Apr 23 '15 08:04 apricot13

Thanks @apricot13

I see all you need to change is in your HTML code, FROM:

<html data-ng-app="myApp">

TO:

<html ng-app="myApp">

As you mentioned above, I am not sure what I can do to fix this issue for future?

perminder-klair avatar Apr 24 '15 09:04 perminder-klair

This corrected my issue to with injector :+1:

Thanks @melino !

I have solved this by including $injector to the ngSoundManager.factory and changed var angularPlayer = injector.get('angularPlayer'); to var angularPlayer = $injector.get('angularPlayer'); (you can get rid of the lines above within the if statement)

numerized avatar Dec 02 '15 00:12 numerized

@perminder-klair the quick and dirty fix would be to include support for both types, I used data- because of cross browser issues (If I remember correctly!)

var elem = angular.element(document.querySelector('[ng-app]'));

apricot13 avatar Dec 02 '15 15:12 apricot13

I got the same pb (using data-ng-app instead of ng-app)

What about using these instruction instead ?

var elem = angular.element(document.querySelector('[ng-app],[data-ng-app]'));

I tested and it seems to work.

msieurtoph avatar Mar 19 '17 02:03 msieurtoph