I’m trying to implement niftyplayer (http://www.varal.org/media/niftyplayer/), into a site with a small list of links. Right now, the player works just fine. I can click on a link:
<a href="javascript:niftyplayer('niftyPlayer1').loadAndPlay('THESONG')">CLICKME</a>
and it will load and play the file via js:
this.loadAndPlay = function (url) {
this.load(url);
this.play();
};
Within the niftyplayer itself, the actionscript that’s called is as follows:
Here’s the AS to load the song:
function prepareNewSong()
{
song = new Sound();
pauseStopSong();
songPosition = 0;
currentRetry = 0;
playingState = 'stopped';
loadingState = 'empty';
onPlay_signaled = false;
// aniBar.gotoAndStop('stop');
d_txt.text = 'ready';
song.onSoundComplete = function()
{
play_btn.play_pause.gotoAndStop('play');
songPosition = 0;
playingState = 'finished';
d_txt.text = '(' + formatTime(sP)+ ') stopped';
if (onSongOver != false) getURL('javascript:'+onSongOver);
}
song.onLoad = function()
{
loadingState = 'loaded';
if (onBufferingComplete != false) getURL('javascript:'+onBufferingComplete);
}
}
AND here’s the AS to play the song:
function playSong() {
aniBar.gotoAndPlay('start');
play_btn.play_pause.gotoAndStop('pause');
if (loadingState == 'empty')
{
d_txt.text = 'setting up...'; ////// never stays at this :(
timeLoadingStarted = (new Date()).getTime();
setInterval(songError, maxWait);
loadingState = 'loading';
song.loadSound(currentSong,true);
d_txt.text = 'buffering...';
if (onBufferingStarted != false) getURL('javascript:'+onBufferingStarted);
}
song.start(songPosition);
playingState = 'playing';
}
My problem is that, although the js function currently loads and plays the song, I need the songs to be able to toggle on or paused once loaded… I CANNOT for the life of me figure this out…
There IS a separate function in niftyplayer to toggle:
function playToggle()
{
if (playingState == 'playing') // pause
{
pauseSong();
}
else // play
{
onPlay_signaled = false;
playSong();
}
}
BUT, it just toggles… it doesn’t load the song into the player first.
Anyone have any ideas?