12/03/2010, 05:14
|
| | Fecha de Ingreso: marzo-2008
Mensajes: 228
Antigüedad: 16 años, 9 meses Puntos: 12 | |
Respuesta: Flash MP3 Player + xml solo funciona en LOCAL (en servidor no) ... ayuda!
Código:
//convertTime() uses this to slice up text
function strPad( str, places, pad, side ){
while ( str.length < places ){
if ( side == "left" ) str = pad + str;
else str = str + pad;
}
var lengthTester = str.toString();
if(lengthTester.length <= 1){
str = "0"+str;
}
return str;
}
//converts time to minutes and seconds on mp3
function convertTime(t,type){
var time = Math.ceil(t);
var min = Math.floor(time/60);
var secs = time-(min*60);
return min + ":" + strPad( time % 60, 2, 0, "left" );
}
//loads mp3 file with sent in mp3 file and title
function loadMP3(mp3File,title){
my_sound = new Sound();
my_sound.onSoundComplete = function(){
if(autoNextSong){
nextSong();
}
}
my_sound.onLoad = function(success:Boolean){
if (success){
loadingNew = false;
if(btnVolume.volumeNum == undefined){
btnVolume.volumeNum = 10;
}
//if in mute mode
if(btnVolume.icon._currentframe == 1){
my_sound.setVolume(btnVolume.volumeNum*10);
}else{
my_sound.setVolume(0);
}
if(btnVolume == undefined){
my_sound.setVolume(100);
}
playStatus = true;
btnPlay.gotoAndStop("stillPause");
loadBar.lines.gotoAndPlay("end");
duration = this.duration/1000;
//move dragger to current location
var currentTime = my_sound.position/1000;
var perc = currentTime/duration;
seekTo(Math.round(loadBar.bar._x + perc*(loadBar.bar._width)),true);
//var myDragger = loadBar.dragger;
//_level0.Tween.tween(myDragger,"_x",Math.round(loadBar.bar._x + perc*(loadBar.bar._width))+"","20","easeInOutQuart");
timer.onEnterFrame = function(){
if(this._parent.loadingNew == false){
var currentTime = my_sound.position/1000;
TFtime.text = convertTime(currentTime)+"/"+convertTime(duration);
if(dragging != true && seeking == undefined){
var perc = currentTime/duration;
var newX = Math.round(loadBar.bar._x + perc*(loadBar.bar._width));
if(newX + loadBar.dragger._width > loadBar.bar._x+loadBar.bar._width){
newX = loadBar.bar._x+loadBar.bar._width - loadBar.dragger._width;
}
loadBar.dragger._x = newX;
}else if(dragging){
//scan through movie using dragger
var perc = (loadBar.dragger._x-loadBar.barProgress._x)/loadBar.barProgress._width;
soundPos = duration*perc;
if(perc < .95){
my_sound.start(soundPos);
if(playStatus != true){
if(pausedOn != true){
pauseMusic();
}
}
}
}
}else{
TFtime.text = "loading...";
}
}
//automatically play the first song
if(autoPlay != true){
stopMusic();
}
}else{
TFtitle.text = "Error loading mp3 file.";
}
}
loadBar.lines.gotoAndPlay(2);
loadingNew = true;
my_sound.loadSound(mp3File,true);
if(autoPlay != true){
stopMusic();
}
loadBar.dragger._x = 0;
TFtitle.text = title;
clearInterval(loaded_interval);
loaded_interval = setInterval(checkBytesLoadedSound, 50);
}
//checking the mp3 download and displaying data
function checkBytesLoadedSound() {
var loaded = my_sound.getBytesLoaded();
var total = my_sound.getBytesTotal();
var myRef = loadBar;
loadBar.barProgress._width = Math.ceil(loaded/total*(loadBar.bar._width));
var pctLoaded:Number = Math.round(loaded/total*100);
if (pctLoaded>=100 && total > 20){
loadBar.barProgress._width = loadBar.bar._width;
clearInterval(loaded_interval);
}else{
TFtime.text = "loading...";
}
}
//moves dragger to given x position
function seekTo(newX,dontStop){
if(dontStop){
dragging = undefined;
}else{
dragging = true;
}
var myRef = loadBar.dragger;
var myFunc = this+".seekingDone";
_level0.Tween.tween(myRef,"_x",newX+"","20","easeInOutQuart",myFunc);
}
//when dragger is done seeking, this function is played
function seekingDone(){
dragging = undefined;
if(pausedOn){
if(firstOn == undefined){
firstOn = true;
if(autoPlay){
playMusic();
}
}else{
playMusic();
}
}
}
//plays next song in list
function nextSong(){
soundPos = 0;
pausedOn = false;
playStatus = true;
dragging = false;
songNum++;
if(songNum >= Music.length){
songNum = 0;
}
this["btnNum"+previousSong].gotoAndPlay("out");
this["btnNum"+songNum].gotoAndStop("active");
previousSong = songNum;
loadMP3(Music[songNum].mp3File,Music[songNum].title);
}
//code for all buttons
function buildNav(){
//DRAGGER
var myRef = loadBar.dragger;
myRef.onPress = function(){
if( this._parent._parent.loadingNew != true){
if(playStatus || pausedOn){
this._parent._parent.dragging = true;
startDrag(this,false,this._parent.barProgress._x, this._y, this._parent.barProgress._x+this._parent.barProgress._width-this._width, this._y);
this._parent._parent.pauseMusic();
}
}
}
myRef.onRelease = myRef.onReleaseOutside = function(){
if( this._parent._parent.loadingNew != true){
this._parent._parent.dragging = false;
this.stopDrag();
this._parent._parent.playMusic();
}
}
//PROGRESS BAR
var myRef = loadBar.barProgress;
myRef.onPress = function(){
if( this._parent._parent.loadingNew != true){
if(playStatus || pausedOn){
var myX = Math.round(this._xmouse * this._xscale/100);
if(myX > loadBar.barProgress._width-loadBar.dragger._width){
myX = loadBar.barProgress._width - loadBar.dragger._width;
}
seekTo(myX);
}
}
}
//PLAY
var myRef = btnPlay;
myRef.onPress = function(){
if(playStatus){
pauseMusic();
}else{
playMusic();
}
}
myRef.onRollOver = function(){
if(playStatus){
this.gotoAndPlay("overPause");
}else{
this.gotoAndPlay("overPlay");
}
}
myRef.onRollOut = myRef.onDragOut = function(){
if(playStatus){
this.gotoAndPlay("outPause");
}else{
this.gotoAndPlay("outPlay");
}
}
//STOP, BACK AND NEXT
btnStop.onRollOver = btnBack.onRollOver = btnNext.onRollOver = function(){
this.gotoAndPlay("over");
}
btnStop.onDragOut = btnBack.onDragOut = btnNext.onDragOut = btnStop.onRollOut = btnBack.onRollOut = btnNext.onRollOut = function(){
this.gotoAndPlay("out");
}
btnStop.onPress = function(){
stopMusic();
}
btnBack.onPress = function(){
songNum-=2;
if(songNum < -1){
songNum = Music.length-2;
}
nextSong();
}
btnNext.onPress = function(){
nextSong();
}
//VOLUME
//code inside btnVolume
//NUMBER BUTTONS
var myCount = Music.length;
var numberButtonMargin = 5;
if(myCount > 1){
for(var i=0;i<myCount;i++){
if(i>0){
btnNum0.duplicateMovieClip("btnNum"+i,i+1);
}
var myRef2 = this["btnNum"+i];
myRef2._alpha = 100;
myRef2._x = Math.round(this["btnNum"+(i-1)]._x + this["btnNum"+(i-1)]._width) + numberButtonMargin;
var myWidth = myRef2._width;
myRef2.icon.TFnumber.autoSize = true;
myRef2.icon.TFnumber.text = i+1;
myRef2.icon.TFnumber._x = 0 + myWidth/2 - myRef2.icon.TFnumber._width/2 - 2;
myRef2.onRollOver = function(){
if(this._parent.songNum != int(this._name.slice(6))){
this.gotoAndPlay("over");
}
}
myRef2.onDragOut = myRef2.onRollOut = function(){
if(this._parent.songNum != int(this._name.slice(6))){
this.gotoAndPlay("out");
}
}
myRef2.onPress = function(){
this._parent.songNum = int(this._name.slice(6))-1;
this._parent.nextSong();
}
}
}else{
btnNum0._visible = false;
}
songNum = -1;
nextSong();
}
//plays music from current position
function playMusic(){
pausedOn = false;
playStatus = true;
dragging = false;
my_sound.start(soundPos);
btnPlay.gotoAndStop("stillPause");
}
//pauses music and saves position
function pauseMusic(){
pausedOn = true;
playStatus = false;
soundPos = my_sound.position/1000;
my_sound.stop();
btnPlay.gotoAndStop("stillPlay");
}
//stops music
function stopMusic(){
playStatus = false;
dragging = true;
loadBar.dragger._x = 0;
my_sound.stop();
btnPlay.gotoAndPlay("stillPlay");
}
//load xml file and organizes the data loaded
function loadXML(){
x = new XML();
x.ignoreWhite = true;
x.onLoad = function(success) {
if(success){
Music = new Array();
var myCount = x.firstChild.childNodes.length;
var rootHandler = x.firstChild.childNodes;
if(x.firstChild.attributes.autoPlay == "true"){
autoPlay = true;
}else{
autoPlay = false;
}
if(x.firstChild.attributes.autoNextSong == "true"){
autoNextSong = true;
}else{
autoNextSong = false;
}
var myRef = Music;
for(var i=0;i<myCount;i++){
var temp1 = new Object();
var myRef2 = temp1;
var myCount2 = rootHandler[i].childNodes.length;
var secHandler = rootHandler[i].childNodes;
for(var y=0;y<myCount2;y++){
myRef2[secHandler[y].nodeName] = ""+secHandler[y].childNodes;
}
Music.push(temp1);
}
buildNav();
delete x;
}else{
TFtitle.text = "ERROR: Could not load XML";
}
}
x.load("mp3Player.xml");
}
//sets up key elements for later use
_level0.Tween = new AnimTween();
System.useCodepage=true;
//loads xml which will then initiate the player
loadXML();
stop();
|