Visualizzazione dei risultati da 1 a 5 su 5

Discussione: autostart player music

  1. #1

    autostart player music

    Ciao a tutti ragazzi e buon anno,

    ho scaricato dalle risorse in flash un player in actionscript e vorrei che la musica partisse da sola, ma non so cosa devo cambiare,

    mi potreste aiutare?

    Grazie.

    codice:
    stop(); // numbers needed for the visuals, you can play around with altering them const PLOT_HEIGHT:int = 11; const CHANNEL_LENGTH:int = 100; // Byte array also needed for the visuals var bytes:ByteArray = new ByteArray(); // Assign The mp3 to play var req:URLRequest = new URLRequest("song.mp3"); // Boolean value for button functions, to switch in the conditionals var isPlaying:Boolean = false; // Create the sound object var snd:Sound = new Sound(req); // Assign a var name for the sound channel var channel:SoundChannel;  // Play Button Listener /////////////////////////////////////////////////////////////////////// playBtn.addEventListener(MouseEvent.CLICK, playPause);  /////////////////////////// Start Play button function ////////////////////////////////////////////////////// function playPause(event:MouseEvent):void {  	// This conditional makes the magic of our play/pause functionality     if (isPlaying == false) {        channel = snd.play(); // Start playing 	   isPlaying = true;     }   // Stop button listener and function stopBtn.addEventListener(MouseEvent.CLICK, stopSound);      function stopSound(event:MouseEvent):void {        channel.stop();        isPlaying = false;     }  // On playback complete listener and function, needed to reset some things channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);      function onPlaybackComplete(event:Event) {  	    isPlaying = false;         //trace("The sound has finished playing.");     }  } /////////////////////////// End Play button function //////////////////////////////////////////////////////    // Add listener to trigger [onEnterFrame] function below, needed for our amplitude animation addEventListener(Event.ENTER_FRAME, onEnterFrame);  function onEnterFrame(event:Event):void { 	 SoundMixer.computeSpectrum(bytes, false, 0); var g:Graphics = this.graphics; g.clear(); g.lineStyle(0, 0x82C0FF); g.beginFill(0x82C0FF, 0.5); g.moveTo(0, PLOT_HEIGHT);  var n:Number = 0;  // left channel for (var i:int = 0; i < CHANNEL_LENGTH; i++)  { n = (bytes.readFloat() * PLOT_HEIGHT); g.lineTo(i * 2, PLOT_HEIGHT - n); } g.lineTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT); g.endFill();  // right channel g.lineStyle(0, 0xFFCC00); g.beginFill(0xFFCC00, 0.5); g.moveTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);  for (i = CHANNEL_LENGTH; i > 0; i--)  { n = (bytes.readFloat() * PLOT_HEIGHT); g.lineTo(i * 2, PLOT_HEIGHT - n); } g.lineTo(0, PLOT_HEIGHT); g.endFill(); } // END onEnterFrame Function

  2. #2
    certo che un codic in orizzontale è comodo=
    Photogallery Flash Gratis - http://www.flashfiles.biz -
    Template in Flash con pannello di Amministrazione e deeplinking Guarda il template qui

  3. #3
    Nessuno ha un' idea di cosa cambiare per far partire la musica in automatico?

    Non penso sia una cosa difficile, lo è per me che di actionscript non ne so nulla!

    Ciao e grazie

  4. #4
    Utente di HTML.it L'avatar di Sleter
    Registrato dal
    Aug 2005
    Messaggi
    465
    Ciao

    Non è che nessuno ha un' idea di come fare per aiutarti a risolvere il problema ma come ironicamente ha cercato di farti notare jjletho, non è questo il modo di proporre un codice.

    La prossima volta usa i tag PHP in modo di agevolarne la lettura del codice oppure passa il link dove hai scaricato il file.

    Comunque il codice per far partire la musica senza dover cliccare sul pulsante "playBtn" va modificato così:

    Codice PHP:
    stop();
    const 
    PLOT_HEIGHT:int 11;
    const 
    CHANNEL_LENGTH:int 100;
    var 
    bytes:ByteArray = new ByteArray();
    var 
    req:URLRequest = new URLRequest("song.mp3");
    var 
    isPlaying:Boolean true;
    var 
    snd:Sound = new Sound(req);
    var 
    channel:SoundChannel;

    channel snd.play();

    playBtn.addEventListener(MouseEvent.CLICKplayPause);
    function 
    playPause(event:MouseEvent):void
    {
        if (
    isPlaying == false)
        {
            
    channel snd.play();
        }
    }
    stopBtn.addEventListener(MouseEvent.CLICKstopSound);
    function 
    stopSound(event:MouseEvent):void
    {
        
    channel.stop();
        
    isPlaying false;
    }
    channel.addEventListener(Event.SOUND_COMPLETEonPlaybackComplete);
    function 
    onPlaybackComplete(event:Event)
    {
        
    isPlaying false;
        
    trace("The sound has finished playing.");
    }
    addEventListener(Event.ENTER_FRAMEonEnterFrame);
    function 
    onEnterFrame(event:Event):void
    {
        
    SoundMixer.computeSpectrum(bytesfalse0);
        var 
    g:Graphics this.graphics;
        
    g.clear();
        
    g.lineStyle(00x82C0FF);
        
    g.beginFill(0x82C0FF0.5);
        
    g.moveTo(0PLOT_HEIGHT);
        var 
    n:Number 0;
        for (var 
    i:int 0CHANNEL_LENGTHi++)
        {
            
    = (bytes.readFloat() * PLOT_HEIGHT);
            
    g.lineTo(2PLOT_HEIGHT n);
        }
        
    g.lineTo(CHANNEL_LENGTH 2PLOT_HEIGHT);
        
    g.endFill();
        
    g.lineStyle(00xFFCC00);
        
    g.beginFill(0xFFCC000.5);
        
    g.moveTo(CHANNEL_LENGTH 2PLOT_HEIGHT);
        for (
    CHANNEL_LENGTH0i--)
        {
            
    = (bytes.readFloat() * PLOT_HEIGHT);
            
    g.lineTo(2PLOT_HEIGHT n);
        }
        
    g.lineTo(0PLOT_HEIGHT);
        
    g.endFill();

    Ho cambiato il valore della variabile "isPlaying" a true e aggiunto snd.play(); fuori dalla funzione richiamata dal pulsante playBtn.
    Ho inoltre spostato listener e funzione abbinate al pulsante "stopBtn" al di fuori della funzione "playPause" perchè altrimenti, tale funzione sarebbe stata chiamata solo a Mp3 in esecuzione.

    Il resto del codice riguarda la barra animata con il metodo computeSpectrum, non c'è nulla da modificare e funziona così comè, l'ho postato comunque qualora interessi a qualcuno.

    ciao

  5. #5
    Molte grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.