Jump to content


Photo

Stuck with Funky's MP3 player


  • Please log in to reply
16 replies to this topic

#1 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 11 March 2007 - 10:39 AM

I've used Funky's tutorial, which has worked like a charm, but I'm trying to just tweak a few things.
The player is on a different frame, which is accessed by clicking the correct Nav Bar link. This works fine.
Visitors can then browse the rest of the website with songs still playing in the background.
The problem I have is that if they go back into the player, the timer kind of glitches out and the song is stopped and a new one started. I'd liek the timers to work properly, and for the song to carry on, rather than a new one starting.
My live example is here: http://www.nonplayer...o.uk/bands/tbc/
(Go to Media > Player)

here is the code I'm using on the player page:
stop();
display_txt.autoSize = "left";
	mutebeat = true;
	Beat1.stop();
	stopAllSounds();
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
	if (success) {
		_global.songname = [];
		_global.songband = [];
		_global.songfile = [];
		for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
			_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
			_global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
			_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
			//trace(songname[i]+" "+songfile[i]+" "+songband[i]);
		}
	}
	_root.createEmptyMovieClip("sound_mc", 1);
	_global.song_nr = random(songfile.length);
	playing = true;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
};
function timer(sound_obj) {
	time = sound_obj.position/1000;
	min = Math.floor(time/60);
	min = (min<10) ? "0"+min : min;
	sec = Math.floor(time%60);
	sec = (sec<10) ? "0"+sec : sec;
	timeDisplay_txt.text = min+":"+sec;
}
MovieClip.prototype.songStarter = function(file, name, band) {
	if (this.sound_obj) {
		this.sound_obj.stop();
		delete this.sound_obj;
	}
	this.sound_obj = new Sound(this);
	this.sound_obj.loadSound(file, true);
	this.onEnterFrame = function() {
		if (this.sound_obj.position>0) {
			delete this.onEnterFrame;
			this._parent.display_txt.text = this._parent.display_txt.text=name+" - "+band;
			this._parent.display_band.text = songband[song_nr];
			timeInterval = setInterval(timer, 1000, this.sound_obj);
			setInterval(soundStatus, 100);
		} else {
			this._parent.display_txt.text = "loading...";
		}
	};
	this.sound_obj.onSoundComplete = function() {
		clearInterval(timeInterval);
		this._parent.timeDisplay_txt.text = "00:00";
		(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
		_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
	};
	this._parent.volume2.drag2.onPress = function() {
		startDrag(this, true, this._x, this._parent.volBG2._height, this._x, 0);
		this.onEnterFrame = function() {
			var p = (this._y/this._parent.volBG2._height)*100;
			var vp = 100-p;
			this._parent._parent.sound_mc.sound_obj.setVolume(vp);
		};
	};
	this._parent.volume2.drag2.onRelease = function() {
		delete this.onEnterFrame;
		stopDrag();
	};
	this._parent.volume2.drag2.onReleaseOutside = function() {
		stopDrag();
	};
};
btn_play.onRelease = function() {
	if (pause == true) {
		this._parent.sound_mc.sound_obj.start(posiP);
		pause = false;
		playing = true;
	} else {
		clearInterval(timeInterval);
		this._parent.timeDisplay_txt.text = "00:00";
		this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
		playing = true;
	}
};
btn_stop.onRelease = function() {
	clearInterval(timeInterval);
	this._parent.timeDisplay_txt.text = "00:00";
	this._parent.sound_mc.sound_obj.stop();
	pause = false;
	playing = false;
};
btn_next.onRelease = function() {
	clearInterval(timeInterval);
	this._parent.timeDisplay_txt.text = "00:00";
	(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
};
btn_prev.onRelease = function() {
	clearInterval(timeInterval);
	this._parent.timeDisplay_txt.text = "00:00";
	(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
	_root.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr]);
};
btn_pause.onRelease = function() {
	//pause button function
	this._parent.sound_mc.sound_obj.stop();
	//stop the current sound
	posiP = _root.sound_mc.sound_obj.position/1000;
	// save the current position in a new variable and divide by 1000 (ms -> sec)
	pause = true;
	//set the variable pause to true
};
function soundStatus() {
	var amountLoaded = _root.sound_mc.sound_obj.getBytesLoaded()/_root.sound_mc.sound_obj.getBytesTotal();
	_root.loader.loadBar._width = amountLoaded*170;
	duration = _root.sound_mc.sound_obj.duration;
	position = _root.sound_mc.sound_obj.position;
	_root.playHead._x = position/duration*161+228;
}
function duration() {
	timed = _root.sound_mc.sound_obj.duration/1000;
	mind = Math.floor(timed/60);
	mind = (mind<10) ? "0"+mind : mind;
	secd = Math.floor(timed%60);
	secd = (secd<10) ? "0"+secd : secd;
	totalDuration = mind+":"+secd;
}
playlist.load("xml/playlist.xml");
setInterval(duration, 100);
setInterval(soundStatus, 100);

thanks

#2 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 11 March 2007 - 06:15 PM

Put a big if statement around it checking for a variable that you set on the root the first time you get to the mp3 player frame.

#3 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 12 March 2007 - 10:38 AM

Put a big if statement around it checking for a variable that you set on the root the first time you get to the mp3 player frame.


I tried verious if statements but nothing seemed to work, closest I got was the track carries on playing but a new track also plays, so there's 2 playing.
I'm guessing you mean if everything other than the button code? Do I need to list the loading of the playlist too?

#4 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 12 March 2007 - 11:01 AM

Basically your problem is that when you click on the nav button to load up the mp3 player, it will start reseting variables and do funky things. One thing you might want to try, is having the mp3 player movieclip along the entire timeline. When your swf starts up, set the visibility of the mp3 player to false, and dont fire the init code yet. Then just make the nav button check the visibility of the nav, if its not visible, make it visible and call the init code. else do nothing.

That should work.

#5 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 12 March 2007 - 08:09 PM

Basically your problem is that when you click on the nav button to load up the mp3 player, it will start reseting variables and do funky things. One thing you might want to try, is having the mp3 player movieclip along the entire timeline. When your swf starts up, set the visibility of the mp3 player to false, and dont fire the init code yet. Then just make the nav button check the visibility of the nav, if its not visible, make it visible and call the init code. else do nothing.

That should work.


I'll give that a shot tomorrow.
Thanks for the help Pax

#6 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 13 March 2007 - 07:16 AM

Ok, I've tried putting an if around the main code, I put antoher if in too to try to make the timer, progress bar and scrolling text to come back once you go into the MP3 player. Unfortunatly it didn't work. The timer and progress bar doesnt work at all anymore. When you go to another page it keeps playing the sound, and carries on playing when you go back into the MP3 page, but no scrolling text or anything appears.

I like the idea of the visibility thing, as then I can just have a button on the main timeline to activate the player so there is no need to go back into the player page. Only a few problems, first one beign that my MP3 player is not in a movie clip, it's on the main timeline in it's own few frames and folder. I tried putting it into it's own clip, but I didn't understand what level it would be, so it didn't work. Which is a shame as I'd love to make it dragable.
The second and most major problem, is that I have no idea how to set visibility ect, I'm still pretty new to Actionscript.

Thanks for the help.

#7 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 13 March 2007 - 07:47 AM

Ok, to set visibility of something, you'll need to use the path to the movieclip (ie. this.myClip.mp3Player) and then change the _visible property. In the end youll have:

this.myClip.mp3Player._visible = true; (or false if you want to hide it);

Once you have the show and hide working, I can help you with the drag functionality.

#8 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 13 March 2007 - 08:25 AM

Ok, to set visibility of something, you'll need to use the path to the movieclip (ie. this.myClip.mp3Player) and then change the _visible property. In the end youll have:

this.myClip.mp3Player._visible = true; (or false if you want to hide it);

Once you have the show and hide working, I can help you with the drag functionality.


So I take it in order to do this I need my MP3 player to be in a movie clip. That's something I'm struggling with, I don't understand the levels.

#9 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 13 March 2007 - 08:52 AM

What exactly do you mean with the levels? Levels really shouldn't matter here. You can put the 3 layers you have for your mp3 player into a movieclip, then put that movieclip on your main timeline.

#10 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 22 March 2007 - 09:08 AM

I'm struggling with getting my player into it's own movie clip. Everytime I put it in to it's own mc, it just doesnt work.
If I PM you with a link to the FLA, do you think you would get time to have a look at it for me and tell me what I'm doing wrong? And maybe help me out with the XML Calendar I posted about in another thread?
I really didn't want to ask for someone to look at it for me, but since this project has to be handed in...yesterday, I have no choice.

Thanks for the help either way.

#11 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 22 March 2007 - 10:12 AM

Yup, send me a link...however, I don't think I'll be able to get around to it tonight. We have company coming over for the evening. My suggestion if you are going to take late marks or something is to hand a working version in even if it doesn't have all of the functionality you'd like. Then see if you can hand an updated one in later on.

#12 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 22 March 2007 - 10:30 AM

I've tried to make a working version, just by taking the news and bio pages and using the same method for the events section, but for some strange reason, it doesn't seem to want to get the XML data, it's very strange.
I've been given a 1 week extention max on this.
I don't expect you to do it instantly, only when you have time to have a look. Thank you for helping me though, it's much appretiated.

I'll PM you the links to 2 versions.

#13 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 25 March 2007 - 01:44 PM

Have you had chance to look at this yet Pax?
I've had a few more attempts but nothing has worked yet.

#14 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 25 March 2007 - 07:23 PM

I've only had a chance to quickly look at it. Most of the problems seem to be caused by scope issues. I'll try to rebuild it so it works inside the movieclip.

#15 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 26 March 2007 - 07:16 PM

Cheers dude.
What do you mean by scope issues? Does that mean where the code is focusing?
As I said before, I'd like to know where I'm going wrong, it's the best way to learn.

Thanks

#16 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 27 March 2007 - 08:51 AM

Scope is like where the code is firing from, and the path required to get it to refer to other elements. The problem with putting your mp3 player inside another movieclip, is that variables are no longer in the right spot, and buttons may not be calling the right functions, etc. because scope has changed. Rather than being on the root, its in a movieclip on the root. It just takes alot of re-working the code to make sure that variables are in the right spot, and code is pointing to functions and vars correctly.

#17 Largo .//npc

Largo .//npc

    Young Padawan

  • Members
  • Pip
  • 38 posts

Posted 27 March 2007 - 09:27 AM

Ah, that's what I meant by levels before, I don't understand how I would go about changing the scope to be pointing in the right direction. Hopefully I'll be able to take a look at your fix and better understand it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users