Jump to content


my record player


  • You cannot reply to this topic
4 replies to this topic

#1 boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 20 June 2007 - 09:21 PM

G'day guys! Go here to check out my record player, built in Flash and using Funky's mp3 code (click on the record or "listen"). As you can see, it's a little complicated, because I've got the arm of the player tied to each song using XML (or FuseXML to be precise, thanks to Andrew!!), plus I have the record spinning, plus I have the mp3 player part in it's own mc, so it's ended up being very messy!

Anyway, my only issue with the player is the volume position - if you try dragging the volume to zero, it works perfectly, but if you then press next or back (or just wait for the next song to start) the volume shoots back up, rather than staying at zero. Here's my code (as I already explained, it's pretty complicated):

import com.mosesSupposes.fuse.*;
ZigoEngine.register(PennerEasing, Fuse);
FuseXML.OUTPUT_LEVEL = 2;
var myfxml:FuseXML = new FuseXML('mp3s/sbplaylist.xml');
myfxml.target = arm_mc;
stop();
_level0.player.btn_play._visible = false;
playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
if (success) {
 _global.songname = [];
 _global.songband = [];
 _global.songfile = [];
 _global.songrotate = [];
 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]);
 }
}
_level0.player.createEmptyMovieClip("sound_mc", 1);
_global.song_nr = random(songfile.length);
_level0.player.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], 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;
_level0.player.timeDisplay_txt.text = min+":"+sec;
}
MovieClip.prototype.songStarter = function(file, name, band, sn:Number) {
	trace( sn );
	myfxml.start('tween'+ Number(_global.song_nr+1), true);
if (_level0.player.sound_obj) {
 _level0.player.sound_obj.stop();
 delete _level0.player.sound_obj;
}
_level0.player.sound_obj = new Sound(this);
_level0.player.sound_obj.loadSound(file, true);
_level0.player.sound_obj.setVolume(50);
_level0.player.onEnterFrame = function() {
 if (_level0.player.sound_obj.position>0) {
  delete _level0.player.onEnterFrame;
  _level0.player.display_txt.text = name+" / "+band;
  timeInterval = setInterval(timer, 1000, _level0.player.sound_obj);
  
 } else {
  _level0.player.display_txt.text = "loading...";
 }
};
_level0.player.sound_obj.onSoundComplete = function() {
 clearInterval(timeInterval);
 _level0.player.timeDisplay_txt.text = "00:00";
 (song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
 _level0.player.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], song_nr);
};
_level0.player.volume1.dragger.onPress = function() {
 startDrag(this, true, 0, this._y, _level0.player.volume1.volBG._width, this._y);
 _level0.player.onEnterFrame = function() {
  var p = (_level0.player.volume1.dragger._x/_level0.player.volume1.volBG._width)*100;
  _level0.player.sound_obj.setVolume(p);
 };
};
_level0.player.volume1.dragger.onRelease = function() {
 delete this.onEnterFrame;
 stopDrag();
};
_level0.player.volume1.dragger.onReleaseOutside = function() {
 stopDrag();
};
};
_level0.player.btn_play.onRelease = function() {
	_level0.player.btn_play._visible = false;
	_level0.player.btn_stop._visible = true;
// set this to maximum desired rate
_root.record.maxRate = 10;   
// set this to control the initial acceleration
_root.record.accel = 0.5;   
_root.record.curRate = 0;
_root.record.onEnterFrame=function()
{
  if (this.curRate < this.maxRate)
  {
	this.curRate += this.accel;
  }
  this._rotation += this.curRate;
}
	if (pause == true){ // no comment....
		_level0.player.sound_obj.start(posiP) // start sound from the previously saved position
	}
	else {
clearInterval(timeInterval);
_level0.player.timeDisplay_txt.text = "00:00";
_level0.player.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], song_nr);
	}
};
_level0.player.btn_stop.onRelease = function() {
	_level0.player.btn_stop._visible = false;
	_level0.player.btn_play._visible = true;
_root.record.maxRate = 0;
_root.record.accel = 0.5;
_root.record.curRate = 10;
_root.record.onEnterFrame=function()
{
		if (this.curRate > this.maxRate)
		{
				this.curRate -= this.accel;
		}
		this._rotation += this.curRate;
}
	_level0.player.sound_obj.stop(); //stop the current sound
	posiP = _level0.player.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
}
_level0.player.btn_fw.onRelease = function() {
_root.record.maxRate = 10;   
_root.record.accel = 0.5;   
_root.record.curRate = 0;
_root.record.onEnterFrame=function()
{
  if (this.curRate < this.maxRate)
  {
	this.curRate += this.accel;
  }
  this._rotation += this.curRate;
}
clearInterval(timeInterval);
_level0.player.timeDisplay_txt.text = "00:00";
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_level0.player.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], song_nr);
};
_level0.player.btn_rev.onRelease = function() {
_root.record.maxRate = 10;   
_root.record.accel = 0.5;   
_root.record.curRate = 0;
_root.record.onEnterFrame=function()
{
  if (this.curRate < this.maxRate)
  {
	this.curRate += this.accel;
  }
  this._rotation += this.curRate;
}
clearInterval(timeInterval);
_level0.player.timeDisplay_txt.text = "00:00";
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_level0.player.sound_mc.songStarter(songfile[song_nr], songname[song_nr], songband[song_nr], song_nr);
};
_level0.player.back_btn.onRelease = function() {
	stopAllSounds();
	gotoAndStop("home");
}
playlist.load("mp3s/sbplaylist.xml");
_root.record.maxRate = 10;   
_root.record.accel = 0.5;   
_root.record.curRate = 0;
_root.record.onEnterFrame=function()
{
  if (this.curRate < this.maxRate)
  {
	this.curRate += this.accel;
  }
  this._rotation += this.curRate;
}

I'm hoping someone will be nice enough to look through it and try to figure out why the volume isn't remembering it's position - I'm thinking it's something to do with the levels, maybe? Or a little bit of code is wrong? I'm pretty sure it'd be in here somewhere:

_level0.player.volume1.dragger.onPress = function() {
 startDrongfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
 _level0.playag(this, true, 0, this._y, _level0.player.volume1.volBG._width, this._y);
 _level0.player.onEnterFrame = function() {
  var p = (_level0.player.volume1.dragger._x/_level0.player.volume1.volBG._width)*100;
  _level0.player.sound_obj.setVolume(p);
 };
};
_level0.player.volume1.dragger.onRelease = function() {
 delete this.onEnterFrame;
 stopDrag();
};
_level0.player.volume1.dragger.onReleaseOutside = function() {
 stopDrag();
};
};

...but can't for the life of me figure out the problem. I should also mention that I've rotated the entire volume1 mc -90° , which doesn't seem to have affected the dragger (still works when you drag it), but may be part of the problem here.

It's very frustrating, because the record player works perfectly besides this issue, so I'm desperately hoping someone's kind enough to help out!

Cheers!

Boog :D

#2 Pax

    P2L Jedi

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

Posted 21 June 2007 - 10:50 AM

I think the problem is in the songStarter code. The sound obj is deleted, thus the current volume is lost AND the volume is set to 50. Create a var for the current volume and set the volume of the new soundObj to equal that var. I did it in the code below...but try it for yourself first then see what I did :winner:

This should all work...of course it hasn't been tested, but yeah. Good luck Boog.

MovieClip.prototype.songStarter = function(file, name, band, sn:Number) {
	trace( sn );
	myfxml.start('tween'+ Number(_global.song_nr+1), true);
if (_level0.player.sound_obj) {
_level0.player.sound_obj.stop();
var nCurrentVol:Number = _level0.player.sound_obj.getVolume();
delete _level0.player.sound_obj;
}
_level0.player.sound_obj = new Sound(this);
_level0.player.sound_obj.loadSound(file, true);
if(nCurrentVol == undefined){
var nCurrentVol:Number = 50; // Change this value to change the default value
}
_level0.player.sound_obj.setVolume(nCurrentVol);
//_level0.player.sound_obj.setVolume(50);
_level0.player.onEnterFrame = function() {
if (_level0.player.sound_obj.position>0) {
  delete _level0.player.onEnterFrame;
  _level0.player.display_txt.text = name+" / "+band;
  timeInterval = setInterval(timer, 1000, _level0.player.sound_obj);
  
} else {
  _level0.player.display_txt.text = "loading...";
}
};


#3 boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 21 June 2007 - 07:44 PM

Pax, you're a legend! I'll try it in a few minutes and let you know how I go. One weird thing is that the original code by Funky doesn't have this bug, which implies that I accidentally changed/deleted something from the code - anyway, I'll give this a go!

;):):(

#4 boogooloo1

    Young Padawan

  • Members
  • Pip
  • 116 posts

Posted 21 June 2007 - 09:08 PM

Works perfectly, mate - I studied what you did, and it was an education, thank you! I wouldn't have been able to come up with that by myself, but hopefully will one day :)

#5 Pax

    P2L Jedi

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

Posted 21 June 2007 - 10:11 PM

Just takes practice mate :)

Practice or many many long days at work smashing your face on your keyboard in frustration.

I suggest the practice. Much easier.

Joking aside -- glad you got it working :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users