perminder-klair / angular-soundmanager2

SoundManager2 Music Player for AngularJs
http://perminder-klair.github.io/angular-soundmanager2/
MIT License
169 stars 108 forks source link

Error when sound finishes #21

Open diegolz opened 9 years ago

diegolz commented 9 years ago

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 commented 9 years ago

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.

melino commented 9 years ago

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)

apricot13 commented 9 years ago

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);
                            }
                        }
neoighodaro commented 9 years ago

Shouldnt this be fixed by the maintainer

perminder-klair commented 9 years ago

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

apricot13 commented 9 years ago

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.

perminder-klair commented 9 years ago

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?

numerized commented 8 years ago

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)

apricot13 commented 8 years ago

@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]'));

msieurtoph commented 7 years ago

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.