Question

I have a literal JS object that create and plays my playlist. In the HTML page I have a list with all my tracks. When I click on some track all works fine but when I click in one track and wait the end of track, the next track not play. this is the part of my code:

   playSound : function(track){
        console.log("Play this song");



        DG_PLAYER.TrackPlaying = track;

        soundManager.destroySound('MySoundID');



                DG_PLAYER.Sound =   soundManager.createSound({
                                        id:'MySoundID',
                                        url:track.sound,
                                        autoLoad: true,
                                        autoPlay: true,
                                        onload: function() { console.log('sound loaded!', this); },
                                        onfinish: function(){
                                            console.log('end song');
                                    var nextSong = DG_PLAYER.getNextSong();
                                            DG_PLAYER.playSound(nextSong);
                                        },
                                        onfailure : function(){console.log('some error')},
                                        whileloading : function(){console.log('i m loading');},
                                        whileplaying : function(){console.log('i m playing');}
                                    });


    },

If I change the line on onfinish event like this : setTimeOut(function(){DG_PLAYER.playSound(nextSong);},2000) it works fine. Some one can help me ?

One other things, when the first song finish and call Play for next Song the track is not loaded (no message back from onload event). Thanks, and sorry for my bad English. A.

OK , I try to add "flashVersion: 9" on setup and this fix the problem but on IE 8 I have un action script message now.

Was it helpful?

Solution

From SoundManager2's Revision History:

Flash Player 11.6.602.171, released by Adobe on 02/26/2013, introduced an issue with SM2's default Flash 8 (flashVersion: 8) API-based JS/Flash interaction, where SM2 methods called from callbacks such as onfinish() would not work. This primarily broke methods used for playing sounds in sequence, serially loading a series of sounds and so on. (See discussion for more.)

Note that this does not affect cases where soundManager.setup({ flashVersion: 9}) is being used; however, SM2 does use flashVersion: 8 by default.

Specifically, Flash-initiated events (such as a sound finishing) make Flash -> JS calls to the SM2 API, which subsequently call user-specified event handlers. If the user-specified SM2 onfinish() handler immediately calls a SM2 method like play() that makes a JS -> Flash call, this call either silently fails or is blocked. Other JS + Flash libraries that use similar callback patterns may also be affected, if their SWF is built targeting the Flash 8 API.

Suspecting a timing or recursion/stack issue, it was found that introducing a setTimeout(callback, 0) to user-specified SM2 callbacks like onfinish() restored sequential/playlist functionality.

Flash Player 11.6.602.180, relased by Adobe on 3/12/2013, exhibits the same behaviour. To avoid additional hacks, SM2 applies this to all Flash 8-based API callbacks regardless of what version of Flash Player is installed. No regressions are anticipated as a result of this change.

Alternately, this issue can be avoided by using soundManager.setup({ flashVersion: 9 }) as the Flash 9-based API does not appear to have this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top