Foros del Web » Creando para Internet » Flash y Actionscript »

problema boton as3 y reproductor mp3 xml

Estas en el tema de problema boton as3 y reproductor mp3 xml en el foro de Flash y Actionscript en Foros del Web. Hola a todos. mi problema es el siguiente: (flash cs5) as3 En un apartado de mi web tengo colocado un reproductor de mp3 con xml, ...
  #1 (permalink)  
Antiguo 17/06/2011, 08:24
 
Fecha de Ingreso: junio-2011
Mensajes: 23
Antigüedad: 12 años, 10 meses
Puntos: 0
Exclamación problema boton as3 y reproductor mp3 xml

Hola a todos. mi problema es el siguiente:
(flash cs5) as3

En un apartado de mi web tengo colocado un reproductor de mp3 con xml, pero cuando cambio a otro apartado me gustaría que se parara la música del reproductor.

había pensado poner dos funciones a un botón, para parar la música, ya que de momento tengo el siguiente código:

ilustrador_btn.addEventListener(MouseEvent.CLICK,i railustrador1);
function irailustrador1 (event:MouseEvent):void {
gotoAndPlay ("playIlustrador")
}

pero no se cómo añadir la función de parar la música a este script.
muchas gracias.
  #2 (permalink)  
Antiguo 17/06/2011, 16:56
Avatar de Bandit
Moderador
 
Fecha de Ingreso: julio-2003
Ubicación: Lima - Perú
Mensajes: 16.726
Antigüedad: 20 años, 9 meses
Puntos: 406
Respuesta: problema boton as3 y reproductor mp3 xml

Hola stpy:
Bienvenido al Foro.
No dices como cargas el sonido.
Aquí un ejemplo para cargar el sonido y detenerlo al ir a otro frame:
Código actionscript:
Ver original
  1. var miSonido:Sound=new Sound(new URLRequest("nombre.mp3"));
  2. var sc:SoundChannel=miSonido.play();
  3. ilustrador_btn.addEventListener(MouseEvent.CLICK, stopSound);
  4. function stopSound(e:Event):void {
  5.     sc.stop();
  6.     gotoAndPlay("playIlustrador");
  7. }
  8. stop();
Espero haberte sido de ayuda.
__________________
Bandit.
Si no sabes estudia y si sabes enseña.
http://www.banditwebdesign.com/
  #3 (permalink)  
Antiguo 18/06/2011, 12:11
 
Fecha de Ingreso: junio-2011
Mensajes: 23
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: problema boton as3 y reproductor mp3 xml

Perdona, pero ya he visto que faltan datos para que me entiendas...

el archivo que quiero detener no es un .mp3 sino una playlist con varios mp3

el archivo xml está cargado con el siguiente código:

stop();




var myFormat:TextFormat = new TextFormat();
myFormat.color = "0xFFFFFF";
myFormat.size = 13;

list.setRendererStyle("textFormat", myFormat);

//////////////////////////////////////////////////////////////////////////////////////////////////

// Initialize variables
var trackToPlay:String;
var pausePosition:int = 0;
var songURL:URLRequest;
var isPlaying:Boolean = false;
var i:uint;
// Initialize the XML, place the xml file name, initialize the URLRequest
// put URLRequest into a new URLLoader, and add event listener on
// myLoader listening for when the XML loading is complete
var myXML:XML = new XML();
var XML_URL:String = "disco7.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);

// Create the xmlLoaded function. What happens when the XML file is fully read
function xmlLoaded(event:Event):void {

// Place the xml data into the myXML object
myXML = XML(myLoader.data);
// Access song 1 in the XML file to start the player
var firstSong:String = myXML..Song.songTitle[0];
var firstArtist:String = myXML..Song.songArtist[0];
songURL = new URLRequest("mp3_files_disco7/" + firstSong + ".mp3");
status_txt.text = "1. "+firstSong +" - "+firstArtist;
// Run the "for each" loop to iterate through all of the song items listed in the external XML file
for each (var Song:XML in myXML..Song) {

i++; // Increment the song counter by one
// Access the value of the "itemColor" node in our external XML file
var songTitle:String = Song.songTitle.toString();
// Access the value of the "itemLabel" node in our external XML file
var songArtist:String = Song.songArtist.toString();
// Adds each song into the list component through this loop
list.addItem( { label: i+". "+songTitle+" - "+songArtist, songString: songTitle, Artist: songArtist, songNum: i } );

}
var myArray = new Array (0,0);
list.selectedIndices = myArray; // This highlights song 1 by default
gotoAndStop(3);

}



Necesito que al pulsar un botón, se detenga el sonido, y vaya a la etiqueta playIlustrador. Si necesitas otra parte del código dímelo y lo posteo.
Gracias..
  #4 (permalink)  
Antiguo 18/06/2011, 12:14
 
Fecha de Ingreso: junio-2011
Mensajes: 23
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: problema boton as3 y reproductor mp3 xml

Y aquí el código en el frame 3 parte1


stop();
var snd:Sound = new Sound();
var channel:SoundChannel;
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);
snd.load(songURL, context);
channel = snd.play(pausePosition); // Start playing
// Set "isPalying" to true now that song is playing
isPlaying = true;
// Make play button show the pause symbol on it
playBtn.gotoAndStop(2);
// Playlist item click listener
list.addEventListener(Event.CHANGE, itemClick);
// Playlist item click function
function itemClick (event:Event):void {
channel.stop(); // stop play
pausePosition = 0;
status_txt.text = event.target.selectedItem.label + ".mp3";
trackToPlay = event.target.selectedItem.songString;
gotoAndPlay(2);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Stop Button Function
function stopPlayer (event:MouseEvent):void {
channel.stop();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Play & Pause Function //////////////////////////////////////////////////////
function playPause(event:MouseEvent):void {

if (isPlaying == true) {

pausePosition = channel.position;
channel.stop();
playBtn.gotoAndStop(1);
isPlaying = false;

} else {

channel = snd.play(pausePosition);
playBtn.gotoAndStop(2);
isPlaying = true;
}

}
////////////////////////////////////////////////////////////////////////////////////
// Play Next Button Function //////////////////////////////////////////////////////
function playNext(event:MouseEvent):void {
newTrack();
}
////////////////////////////////////////////////////////////////////////////////////
// Play Previous Button Function //////////////////////////////////////////////////////
function previousSound(event:MouseEvent):void {

// set some variables here
var prevNum:uint = list.selectedItem.songNum - 2;
var selectPrevSong = new Array (prevNum,prevNum); // array for cell select
var indexMinus1:uint = i -1; // This takes the index and subtracts 1 from it in order to select the correct song
var lastSongInList = new Array (indexMinus1,indexMinus1); // array for cell select of very last song in list

if (list.selectedItem.songNum == 1) {

if (snd.bytesLoaded != snd.bytesTotal) {
channel.stop();
snd.close();
list.selectedIndices = lastSongInList; // This selects very last song in the list component
list.scrollToIndex(indexMinus1); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
} else {
channel.stop();
list.selectedIndices = lastSongInList; // This selects very last song in the list component
list.scrollToIndex(indexMinus1); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
}

} else {

if (snd.bytesLoaded != snd.bytesTotal) {
channel.stop();
snd.close();
list.selectedIndices = selectPrevSong; // This selects previous song in the list component
list.scrollToIndex(prevNum); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
} else {
channel.stop();
list.selectedIndices = selectPrevSong; // This selects previous song in the list component
list.scrollToIndex(prevNum); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
}

}
pausePosition = 0;
}
// Button Listeners ///////////////////////////////////////////////////////////////////////
stop_btn.addEventListener(MouseEvent.CLICK, stopPlayer);
playBtn.addEventListener(MouseEvent.CLICK, playPause);
previousBtn.addEventListener(MouseEvent.CLICK, previousSound);
nextBtn.addEventListener(MouseEvent.CLICK, playNext);

// Place track amount and current track # into our text field
songCount_txt.text = "Ahora sonando " + list.selectedItem.songNum + " of " + i;

// Event Listener for sound complete when any song finishes
channel.addEventListener(Event.SOUND_COMPLETE, onCompletePlayback);
// Function inSoundComplete
function onCompletePlayback (event:Event):void {
newTrack();
}
// New track play function
function newTrack():void {
if (list.selectedItem.songNum == i) { // if songNum == total track amount
channel.stop(); // stop the player
var selectFirst = new Array (0,0); // array for cell select
list.selectedIndices = selectFirst; // This selects song 1
list.scrollToIndex(0);
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2); // Make the switch and play
} else {
channel.stop(); // stop the player
var sn:uint = list.selectedItem.songNum; // var that has value of current list songNum
var selectNext = new Array (sn,sn); // array for cell select
list.selectedIndices = selectNext; // This selects next song in the list component
list.scrollToIndex(sn);
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2); // Make the switch and play
}
// Always set pausePosition back to 0 here
pausePosition = 0;
} /// Close newTrack function
////////////////////////////////////////////////////////////////////////////////////
  #5 (permalink)  
Antiguo 18/06/2011, 12:15
 
Fecha de Ingreso: junio-2011
Mensajes: 23
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: problema boton as3 y reproductor mp3 xml

parte 3 del código


/////////////// Track Scrubber and Ghost Scrub Knob /////////////////////////////////////////////////////////////////////////////////
// ------------------------------------------------------------------ Along with the follower clip inside the trackScrubber
var isDragging:Boolean;
trackScrubber.ghostKnob.visible = false;
// Set Bounds
var scrubberBounds = new Rectangle(0,trackScrubber.ghostKnob.y,trackScrubbe r.scrubberRect.width,0);
trackScrubber.addEventListener(MouseEvent.MOUSE_DO WN, dragScrub);
stage.addEventListener(MouseEvent.MOUSE_UP, dropScrub);

// Drag scrubber
function dragScrub(evt:Event):void {
trackScrubber.ghostKnob.startDrag(true,scrubberBou nds);
trackScrubber.ghostKnob.visible = true;
isDragging = true;
}
// Drop scrubber
function dropScrub(evt:Event):void {

if (isPlaying == true && isDragging == true) {

stopDrag();
// Calculate full time of this track
var fullTime:int = Math.floor(snd.length / 1000);
// Claim a var for the position the song is where we release the scrubber after dragging
var newPos:Number = fullTime / 100 * Math.floor(trackScrubber.ghostKnob.x * 1000);
// Important to set new pause position here
trackToPlay = list.selectedItem.songString; // Define track to resume
pausePosition = newPos / 2;
channel.stop();
gotoAndPlay(2);
//channel = snd.play(newPos);
isPlaying = true;
isDragging = false;

} else { // if not playing
isDragging = false;
trackScrubber.ghostKnob.visible = false;
//pausePosition = fullTime / 100 * Math.floor(trackScrubber.tBarKnob.x * 1000);

}

}
/////////////// End Track Scrubber and Seek Bar //////////////////////////////////////////////////////////////////////////////////////////////


// Set up the onEnterFrame Event for EQ and other various things we may add later on
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {

// ANIMATED EQ BARS CODE
eqBarLeft1.gotoAndStop (Math.round(channel.leftPeak * 10) ); // 10 is the amount of frames in our EQbar clips
eqBarRight1.gotoAndStop (Math.round(channel.rightPeak * 8) ); // 10 is the amount of frames in our EQbar clips
eqBarLeft2.gotoAndStop (Math.round(channel.leftPeak * 7) ); // 10 is the amount of frames in our EQbar clips
eqBarRight2.gotoAndStop (Math.round(channel.rightPeak * 7) ); // 10 is the amount of frames in our EQbar clips
eqBarLeft3.gotoAndStop (Math.round(channel.leftPeak * 8) ); // 10 is the amount of frames in our EQbar clips
eqBarRight3.gotoAndStop (Math.round(channel.rightPeak * 10) ); // 10 is the amount of frames in our EQbar clips

// Set and change volume if they drag
var volumeLevel = channel.soundTransform;
var newLevel:Number = (volumeSlider.knob.x) / -100;
volumeLevel.volume = newLevel;
channel.soundTransform = volumeLevel;
volumeSlider.volumeLightBar.width = volumeSlider.knob.x;

// Get full time of the song
var tallytime = (snd.length/1000);
var totalmins:Number = Math.floor(tallytime /60);
var totalsecs = Math.floor (tallytime) % 60;
if (totalsecs < 10){
totalsecs = "0" + totalsecs;
}
displayFullTime.text = ( " " + totalmins+ ":" + totalsecs);
// End get Full time
// Get playing time of the song
var totalSeconds:Number = channel.position/1000;
var minutes:Number = Math.floor(totalSeconds /60);
var seconds = Math.floor (totalSeconds) % 60;
if (seconds < 10){
seconds = "0" + seconds;
}
displayTime.text = ( " " + minutes+ ":" + seconds);
// End get playing time

/// progress bar code...
var estimatedLength:int = Math.ceil(snd.length / (snd.bytesLoaded / snd.bytesTotal));
var playbackPercent:uint = 100 * (channel.position / estimatedLength );
// I want my position bar to be 200 pixels wide on completion so I multiply the percentage x 2
trackScrubber.positionBar.width = playbackPercent * 2;
trackScrubber.follower.x = trackScrubber.positionBar.width;
// make the loaded progress bar that lives under the playhead progress bar grow dynamically
var loadedPercent:uint = 100 * (snd.bytesLoaded / snd.bytesTotal);
trackScrubber.loadedProgressBar.width = loadedPercent * 2;
}

Etiquetas: musica, parar, reproductor, xml, botones
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:03.