PDA

View Full Version : Need help controlling flash mp3 player with javascript...



qristopher
January 21st, 2009, 06:06 PM
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?

supercain
February 13th, 2009, 12:33 PM
Hi, thats exactly the same script im working right now with. Maybe we can help each other. I dont understand what exactly your problem is but i use this

<a href="javascript:niftyplayer ('FMrPlayer').playToggle()">Play</a>

for toggling between play and pause. Just make sure FMrPlayer' is the id of your player to make it work. You can also use that to control the player from the parent window in case you are using the popup function. Thats the stuff im suffering with right now, because i want to add to the popup a playlist that is already defined, unlike the original code that builds it up as you click on a song in the parent window.

Hope it helps.

RobGetek
October 18th, 2010, 08:49 PM
I'm trying to do the exact same thing you mentioned qristopher (http://www.kirupa.com/forum/member.php?u=38736). I can not figure it out, have you found a solution yet?

Basically, I want the loadAndPlay function to act like the playToggle function when clicked a second time (pausing the currently playing song).