I was wondering if anybody could give me some advice to play from the middle of a song on mobile with soundmanager2. I need it to work on android 4+ and IOS6 and IOS7. I have a solution, but it's not perfect.
I have found that soundmanager2 has unexpected results with playing music from a different start point of the song, and the behaviour varies with different devices.
I have also tried the same solution with pure HTML5 audio using .currentTime, however I have exactly the same problem with HTML5 audio, and as soundmanager2 uses html5 I have a feeling the problem is related.
My solution so far:
I have found that the best way to make sure that the song plays from the correct start point is to change the position after the song starts playing and not before the song song starts playing. However the undesired effect of this is that the song briefly plays before the change of position kicks in . I try to set the volume to 0 and to 100 to 'mask' this but some mobile devices ignore this. The solution works perfectly on desktop, but that's not good enough.
In soundManger the onplay event does not trigger when the song is playing, as it is triggered immediately when I call .play(); . For this to work, I need to use soundManager.onPosition('scAudio', 500, function .. ) and I have found 500 to be adequate to be picked up in most places. If I make it less than that, it wont be picked up in IOS6,
Can anybody assist with a better solution that doesn't mean the song plays before the position change kicks in?
Here is my code so far:
soundManager.setup({
url: '/js/soundmanager2_flash9.swf',
flashVersion: 9,
preferFlash: false,
debugMode: false,
onready: function() {
scAudio = soundManager.createSound({
id: 'scAudio',
url: audioUrl,
autoLoad: true,
volume: 0,
position: startPoint
});
soundManager.onPosition('scAudio', 500, function() {
scAudio.setPosition(startPoint)
soundManager.setVolume('scAudio', 100)
});
}
});
function onThumbnailTouch() {
scAudio.play()
};
Tested in iOS 7, I've had success using the SoundManager "onPosition" event trigger. So I attached something like this to my "click" button event.